here's my code
<?php
$this->widget('zii.widgets.grid.CGridView',array(
'dataProvider'=>$dataProvider,
'columns' => array(
array(
'name' => 'emailaddress',
'htmlOptions' => array(
'width' => '30',
),
),
array(
'name' => 'secretkey',
'htmlOptions' => array(
'width' => '40px',
),
),
array(
'header' => 'Options',
'class' => 'CButtonColumn',
'template' => '{view}{update}{delete}',
),
array(
'header' => 'Copy URLs',
'class' => 'CButtonColumn',
'template' => '{copy}',
'buttons' => array(
'copy' => array(
'label' => 'copy url',
'url' => 'Yii::app()->createUrl("emails/view",array("id"=>$data["emailid"]))',
'options' => array('id' => $data["emailid"]),
'click' => 'function(){$("#mydialog").dialog("open"); return false;}',
)
),
),
),
));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'mydialog',
'options' => array(
'title' => 'URL + Key',
'autoOpen' => false,
'width' => 500,
'height' => 300,
),
));
//THIS PART SHOULD RECEIVE THE ID SO THAT I CAN QUERY TO THE DB TABLE
?>
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
my question is, how will i pass the ID of the clicked row, to the Dialog box? , so that I can use that ID in order to render the correct contents inside the dialog box ?
because with the help of that ID, i can do a db query like this
SELECT u.url,e.secretKey FROM tbl_emails AS e, tbl_urls AS u
WHERE emailid = ID;
Use the jQuery data method.
For example:
<?php
...
'copy' => array(
'label' => 'copy url',
'url' => 'Yii::app()->createUrl("emails/view",array("id"=>$data["emailid"]))',
'options' => array('id' => $data["emailid"]),
'click' => 'function(){$("#mydialog").data("emailid",$(this).attr("id")).dialog("open"); return false;}',
)
...
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'mydialog',
'options' => array(
'title' => 'URL + Key',
'autoOpen' => false,
'width' => 500,
'height' => 300,
'close'=>"js:function(){
$('#mydialog').removeData('emailid');
}",
),
));
// GETTING THE ID
?>
$('#mydialog').data('emailid');
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
Related
I have the following form element configured and i don't know why the values are not preselected.
$this->add(array(
'name' => 'item_ids',
'type' => 'Select',
'attributes' => array(
'id' => 'item_ids',
'class' => 'form-control',
'multiple' => 'multiple',
'value' => array('1','2'),
),
'options' => array(
'label' => 'Items',
'label_attributes' => array(
'class' => 'col-sm-2 control-label',
),
'value_options' => array(
'1' =>'Item 1',
'2' =>'Item 2',
'3' =>'Item 3'
),
)
));
I want that the "Item 1" and "Item 2" are preselected.
I hope someone can help me with my problem.
#### Update ####
Found something like that in the documentation, i will give it a try :
'value_options' => array(
array(
'value' => '1',
'label' => 'Orange',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Lemon',
),
),
you can set form values like :
$form->getElement('selector')->setValue('val');
or
$form->setDefaults(array(
'selector' => 'val'
));
As I mentioned in the Update of my first post, I found something that seemed to be the right way.
I tested it and this is the solution :
$this->add(array(
'name' => 'item_ids',
'type' => 'Select',
'attributes' => array(
'id' => 'item_ids',
'class' => 'form-control',
'multiple' => 'multiple',
),
'options' => array(
'label' => 'Items',
'label_attributes' => array(
'class' => 'col-sm-2 control-label',
),
'value_options' => array(
array(
'value' => '1',
'label' => 'Item 1',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Item 2',
'selected' => true,
),
array(
'value' => '3',
'label' => 'Item 3',
),
),
)
));
Im using Editable Grid extension of CGridview.
MY Grid:
$this->widget('EditableGrid', array(
'dataProvider' => $dataProvider,
'template' => '{items}{pager} ',
'id' => 'PO-grid',
'htmlOptions'=>array(
//'style'=>'width:1100px;'
),
'columns' => array(
array(
'class' => 'EditableGridColumn',
'header' => '',
'name' => 'PO_{gridNum}_{rowNum}_edit',
'imageurl'=> Yii::app()->request->baseUrl.'/images/update.png',
'tag' => 'button',
'tagHtmlOptions' => array(
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'StentysRef',
'name' => '[{gridNum}][{rowNum}]ref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'SupplierRef',
'name' => '[{gridNum}][{rowNum}]productref',
'tag' => 'textField',
'tagHtmlOptions' => array(
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Product',
'name' => '[{gridNum}][{rowNum}]productname',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '2'
'readonly'=>true
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Qty',
'name' => '[{gridNum}][{rowNum}]qty',
'tag' => 'textField',
'tagHtmlOptions' => array(
'size' => '2',
'readonly'=>true,'width'=>'10px','style'=>'width:70px;'
)
),
array(
'class' => 'EditableGridColumn',
'header' => 'Description',
'name' => '[{gridNum}][{rowNum}]description',
'tag' => 'textField',
'tagHtmlOptions' => array(
// 'size' => '5'
'readonly'=>true
)
),
array('class'=>'CButtonColumn','template' => '{delete}',
'buttons'=>array(
'delete' => array(
'options'=>array('style'=>'margin-left:20px'),
'imageUrl'=>\Yii::app()->request->baseUrl.'/images/delete.png', )
),
),
),
));?>
My problem is, Gridview is fit with 1600 X 900 px screen , it should not fit with below px.
Anyone please help me to reolve this problem.
I want to make this grid fit with screen 1366 px.
global.php
return array(
'navigation' => array(
'default' => array(
array(
'label' =>'Home',
'route' => 'home',
'use_route_match' => true,
),
array(
'label'=>'Access',
'route' => 'access',
'constraints' =>
array (
'class' => 'access',
),
'use_route_match' => true,
'pages' => array(
'city'=> array(
'label'=>'City',
'route' => 'city',
'id' => 'city',
'use_route_match' => true,
),
),
),
array(
'label'=>'Privacy',
'route' => 'privacy',
'use_route_match' => true,
),
),
),
);
I'm trying to set a textarea in a Zend Form but it always creates an input type text box.
I read some code using the Zend\Form\Element\Textarea but still no luck
This is how I am doing it in my ProjectForm.php:
$this->add(array(
'name' => 'summary',
'type' => 'Zend\Form\Element\Textarea',
'options' => array(
'label' => 'Resumen',
),
));
And in Project.php I have this
$inputFilter->add($factory->createInput(array(
'name' => 'summary',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 500,
),
),
),
)));
Thanks
Nevermind, I was calling echo $this->formInput instead of echo $this->formTextarea viewHelper.
You have to mention the type in attributes:
$this->add(array(
'name' => 'summary',
'attributes' => array(
'id' => 'summary'
'type' => 'textarea',
'class' => '',
),
'options' => array(
'label' => 'Resumen',
),
)
);
I have an array that has a value with multiple options that is broken down into it's own array. One of those values I want to populate with a loop. Is this possible with the ; in the forloop I would think it would break. What is the best way to accomplish this request?
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array(
for ($x=0; $x<=10; $x++){
array('name' => __($x , 'title'), 'value' => $x)
}
)
),
Here is the complete array outside of what I posted:
$meta_boxes[] = array(
'id' => 'januas_speakers',
'title' => __('Ensemble', 'januas'),
'pages' => array('ja-event'),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => __('Visible', 'januas'),
'desc' => __('Select Yes to show the box in the event page, No to hide it.', 'januas'),
'id' => 'januas_speakers_visible',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Position', 'januas'),
'desc' => __('Select the preferred position for the box.', 'januas'),
'id' => 'januas_speakers_position',
'type' => 'select',
'options' => array(
array('name' => __('Main', 'januas'), 'value' => 'main'),
array('name' => __('Sidebar', 'januas'), 'value' => 'sidebar'),
)
),
array(
'name' => __('Order', 'januas'),
'desc' => __('Insert the box order (ex: 1).', 'januas'),
'id' => 'januas_speakers_order',
'std' => 1,
'type' => 'text_small'
),
array(
'name' => __('Show Title', 'januas'),
'desc' => __('Select Yes to show the box title, No to hide it.', 'januas'),
'id' => 'januas_speakers_showtitle',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => __('Show in Top menu', 'januas'),
'desc' => __('Select Yes to show the menu item in the event page top menu, No to hide it.', 'januas'),
'id' => 'januas_speakers_showinmenu',
'type' => 'select',
'options' => array(
array('name' => __('Yes', 'januas'), 'value' => 'y'),
array('name' => __('No', 'januas'), 'value' => 'n'),
)
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_images_gallery',
'type' => 'image_gallery'
),
array(
'name' => __('Ensemble List', 'januas'),
'desc' => 'Select the ensemble memebers for this event.',
'id' => 'januas_speakers_completelist',
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'januas'),
'value' => $x,
);
}, range(0,11))
),
array(
'name' => __('Display order', 'januas'),
'desc' => '',
'id' => 'januas_speakers_speakersorder',
'type' => 'event_speakers'
),
array(
'name' => '',
'desc' => '',
'id' => 'januas_speakers_backtotop',
'type' => 'backtotop'
)
),
);
You could use array_map:
array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array_map(function ($x) {
return array(
'name' => __($x, 'title'),
'value' => $x,
);
}, range(0,11))
),
You should use array_push
$a = array(
'name' => __('Ensemble List', 'januas'),
'type' => 'checkbox',
'options' => array()
);
for ($x=0; $x<=10; $x++){
array_push( $a['options'], array('name' => __($x , 'title'), 'value' => $x) );
}
print_r($a);
Do you need to run the loop inside of options? How about this approach.
$foo = array();
for ($x=0;$x<10;$x++)
$foo[] = $x;
$bar = array(
'name' => 'hello',
'options' => $foo
);
print_r($bar);
https://eval.in/54925