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 ..
Related
i have a dropdown here in yii that looks like this:
<?php echo $form->dropDownList($model, 'is_enabled',
array('0'=>'No', '1'=>'Yes'), array('id'=>'new-sys-user-is_enabled',));?>
the problem with this is that it shows the 'No' because it has the 0 key. I would like to show the 'Yes' by default. What is the work-around for this?
Check out if this works for you: http://www.yiiframework.com/forum/index.php/topic/11748-dropdownlist-selected-option/
EDIT: Copying the relevant part:
$form->dropDownList($model,'sex',array('1'=>'men','2'=>'women'), array('options' => array('2'=>array('selected'=>true))));
I think you should try like this ...
<?php echo $form->dropDownList($model, 'is_enabled', array('1'=>'Yes', '0'=>'No'), array('id'=>'new-sys-user-is_enabled',));?>
The value you want to keep default value, then keep first in array too.
Thanks
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 have a two tables:
tbl_day:id_day,mon,tues,wed,thurs,fri,sat,sun
tbl_shft:shft_id,start,end,name,status
I want to have a dropdown table in tbl_day where mon is dependent in the tbl_shft name.
I come up with a dropdown that is displaying data from shift. what I did is.
<?php echo $form->labelEx($model,'sun'); ?>
<?php echo CHtml::activeDropDownList($model,'sun',$model -> getCategories(),array('prompt'=>'Select a Shift'))
?>
and for my model
public function getCategories(){
//this function returns the list of categories to use in a dropdown
return CHtml::listData(Shift::model()->findAll(), 'shft_id', 'name');}
My problem is that it is not submitting. I dont know where my problem here is. Im a beginner in Yii. Hope someone helps. Thanks in advance.
In here your code will work. I think the submitted output was not handled correctly. #sam dark says correctly. Edit your question .just place the controller action of your process . Else you just place this code on your controller action. And give the result of controller on this question itself.
Public function actionYouraction(){
......
if(isset($_POST))
{
echo "<pre>";
print_r($_POST);
exit(); } }
I have a dynamic dropdown, data coming from the database.
<?php $sel_id = $selected_id_array[0]->UPR_RelationType;?>
My dropdowm looks like this
<?php echo CHtml::dropDownList('RelationType_'.$pat_id[0]->PAT_ID,'U2U_RelationType',CHtml::listData(MasterTypeItems::model()->findAllByAttributes(array('MSTT_MST_ID'=>$relationship_type_array[0]->MST_ID),array('order' => 'MSTT_Name')), 'MSTT_ID', 'MSTT_Name'),array('id'=>'select','class'=>'relation_type','style'=>'width:50px'));
In this dropdown i have to select defaultly $sel_id;
for example am getting $sel_id=5; In the drop down i have to select 5th option as selected in yii. please give me any suggestion what i have to write in dropDown to select $sel_id;
If I understand your question correctly, what you want to achieve is a dropdownlist which already has a pre-selected option. If so, then this piece of code should work.
echo dropDownList(string $name, string $select, array $data, array $htmlOptions=array ( ))
where $select would be your default selected item.
More information can be found here: http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail
In Yii, CGridView has it's own background color in the row. But what I want to do is highlight particular row based on the value of one of the column.
For Instance, I have three column, id, name, status. Now, If the Value of status is Inactive or 0, I should highlight the row with some color.
I read the class reference briefly and searched this site as well. But could not find the relevant solution. If some example or some direction toward the right solution, that would be much appreciated.
Thanks,
Ujjwal
CGridView 'rowCssClassExpression' is the way to get what you want.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'rowCssClassExpression'=>'($data->myFlag==0)?"normal":"especial"',
'columns'=>array(
...
),
));
You can also call a custom php function, and pass the $data variable to it. That function should return the class name for the given row :)
Use rowCssClass and rowCssClassExpression for your functionality. I did not tested this code but the trick you can use to get your solution.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'rowCssClass'=>array('odd','even'),
'rowCssClassExpression'=>($data->status==0)?even:odd,
'columns'=>array(
),
));