I want to make a condition in displaying a menu item in CMenu by limiting it only to one user ,for example, with the name of 'admin'. I am writing this
'items'=>array(
array('label'=>'Logs','url'=>array('actionLogs/admin'),'icon'=>'wrench white',
'visible'=>!Yii::app()->user->isGuest),
This condition works fine. Next I try to complicate a little the condition of the visibility, but it fails at all
'items'=>array(
array('label'=>'Logs','url'=>array('actionLogs/admin'),'icon'=>'wrench white',
'visible'=>'!Yii::app()->user->isGuest && Yii::app()->user->name=="admin"'),
How can I achieve what I am trying to do? Thanks.
Okay, found the solution. For those who will meet the same problem, here's the code:
'items'=>array(
array('label'=>'Logs','url'=>array('actionLogs/admin'),'icon'=>'wrench white',
'visible'=>(!Yii::app()->user->isGuest && Yii::app()->user->name=="admin")),
and force reload without caching.(Ctrl+F5)
Related
Iam having
<?= $form->field($model, 'parentid')
->dropDownList(ArrayHelper::map(User::find()->asArray()->all(), 'id', 'firstName'),
['prompt'=>'-Select a Parent-'])
?>
When i submit the form,iam getting parentid value is empty.
I have disable the dropdown by jquery
$("#register-parentid").attr("readonly", "readonly");
Im getting empty value and i have referred, as said , we cannot get the value from disable field. Then how can i get the values from disable.
Iam using same form for two functions. One for disable field and another one for non disable .
I tried lot. but i didn't get the solutions for this one.
Finally, I have playing with jquery.
When i submit the form, i have disabling the readonly field
$('button[type=submit]').on('click', function (event, attribute) {
$("#register-parentid").prop("disabled", false);
});
This is my one of the Cgridview Column
array( 'name'=>'furnished',
'type'=>'raw',
'value'=>'$data->furnished=="FF" ? CHtml::link(CHtml::encode($data->furnished),
"tooltip",["title"=>"**Here I Want to show <?php echo $data->anystring ?>**", "data-toggle"=>"tooltip",
"style"=>"text-decoration: none; cursor:pointer;"]) : $data->furnished',
),
How can I achieve this . Please help
normally typed data is displayed here. but how to show PHP variable
Thanks In advance
Everything in value will be executed via PHP's eval() function. So you must change your code to this:
'value'=>'$data->furnished=="FF" ? CHtml::link(CHtml::encode($data->furnished),
"tooltip",["title"=>"**Here I Want to show ".$data->anystring."**", "data-toggle"=>"tooltip",
"style"=>"text-decoration: none; cursor:pointer;"]) : $data->furnished'
Actually, you don't need <?php and all you need is just ..
I have a dropdown that I want to populate when an item in another dropdown is selected. Both the dropdown are tied to data/model passed on from controller. and the first dropdown is populated from DB by calling a function in the model. Heres' the form,
echo $form->dropDownListRow($modelunit,
'superunit',
$model->getSunits(),
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('user/getunits'),
'update'=>'#unit_id',
)));
echo CHtml::dropDownList('unit_id','', array());
Here's the action user/getunits called by Ajax.
$data=Unit::model()->findAll('sid=:sid',
array(':sid'=>(int) $_POST['superunit']));
$data=CHtml::listData($data,'id','name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
I keep getting an error "Undefined index: superunit" when first dropdown is selected. Also, you may notice I am using form->dropDownListRow for the first dropdown while using CHtml::dropDownList for the second. That's cause I am clueless on the syntax of how exactly to make sure the dropdown is populated correctly with ajax and at also properly bind to the model.
You use $form->dropDownListRow that's why you will get $_POST['MyModelName']['superunit'] on your server side
Change you code like
$data=Unit::model()->findAll('sid=:sid',
array(':sid'=>(int) $_POST['MyModelName']['superunit']));
Where MyModelName is a model that you use)
Or like
echo CHtml::dropDownList('superunit'.....
For others - this wiki may help.
I am using Zend form and using it i am creating a multi select box. But when the multiselect box is created the first option value is a empty element.. like this
`<option value=""></option>`
I want to avoid this..This is the code i am using..
$addressType_selected = $this>createElement('multiselect','addressType_selected[]')
-> setAttrib('class','float_left input_width_295 k-multiselectbx')
-> setAttrib('tabindex',43);
$addressType_selected->setDecorators(array(
'ViewHelper',
'Errors'
));
What is wrong with my code.. i am stuck with this... Thanks in advance....
I found the answer..
Just used the following script
$("#addressType_selected option[value='']").remove();
In a functional test in symfony, sfTestBrowser provides methods
click() "Simulates a click on a link or button."
select() "Simulates selecting a checkbox or radiobutton."
and unselect().
But I have not found a way to simulate making a selection from a <select> element.
Does anybody know a way to do this?
This has troubled me too. I'm assuming you just want to set the value for form submission? If you know the value, you can of course just do
$browser->click('Save', array(
'theselectfield' => 'desired_value'
));
But usually I don't know the value I want posted, because it's from a database-driven select box. So my solution is
$theOption = $browser->getResponseDomCssSelector()->matchAll('select[name*=name_of_select_field] option:contains(TheOptionTextYouWant)')->getNode();
$browser->setField('theselectfield', $theOption->getAttribute('value'));
... or use $browser->click() instead ...
Frustrating because you have to break out of the $browser call chain, in order to use getResponseDomCssSelector(), but I haven't found an easier way.