Here is my code
$img= Yii::app()->params['questionImageUploadURL'].$model->q_type."/".$model->qImgRel->image_name;
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'q_nationality_id',
'q_type',
'q_name',
array(
'name' => 'q_image_id',
'value' => (is_object($model->qImgRel)?CHtml::image($img,""):""),
'visible'=>(is_object($model->qImgRel)?true:false),
),
'opt1',
'opt2',
'opt3',
'opt4',
'answer',
),
)); ?>
Its display me like this
I dnt get image in my view
plz help me
Thanks in advance :)
Try this :-
array(
'name' => 'q_image_id',
'type' => 'raw'
'value' => (is_object($model->qImgRel)?CHtml::image($img,""):""),
),
<? php
$w="50px";$h="50px";
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'redcliffe-cms-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'title','date','description',
array(
'filter' => '',
'type' => 'raw',
'value' => 'CHtml::image(Yii::app()->baseUrl ."/upload/" .$data>image,"",array(\'width\'=>\'50\', \'height\'=>\'50\'))',
),
array(
'class' => 'CButtonColumn',
),
),
));
? >
http://www.yiiframework.com/doc/api/1.1/CDetailView#attributes-detail
A simple
array(
'name'=>'filename',
'value'=> CHtml::image(Yii::app()->request->baseUrl.'/path/'.$model->filename),
'type'=>'raw',
),
would do the trick (don't forget the type 'raw')
Related
So I have created records and each has their own particular Service field. They are all filled up (not null).
In the MySQL database, there are also records of that field Service
But in my CGridView, my Service field is all blank. All the Service fields are blank for all the records. When I click on the button View - The one with the magnifying glass, it says Service - Not Set
Can I know what may cause the problem? Please help me Thanks!
UPDATED WITH CGRIDVIEW CODE
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'booking-grid',
'htmlOptions'=>array('class'=>'grid-view grid-size'),
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array(
'name'=>'date',
'htmlOptions'=>array('style'=>'text-align:center', 'height'=>'50px', 'width'=>'80px'),
'headerHtmlOptions'=>array('height'=>'30px'),
),
array(
'name'=>'timeStart',
'header'=>"Time",
'htmlOptions'=>array('style'=>'text-align:center', 'width'=>'80px'),
),
array(
'name'=>'client_id',
'value'=>'GxHtml::valueEx($data->client)',
'filter'=>GxHtml::listDataEx(Client::model()->findAllAttributes(null, true)),
'htmlOptions'=>array('width'=>'200px'),
),
array(
'name'=>'service_id',
'value'=>'GxHtml::valueEx($data->service)',
'filter'=>GxHtml::listDataEx(Service::model()->findAllAttributes(null, true)),
),
array(
'name' => 'complete',
'header'=>'Status',
'value' => '($data->complete == 0) ? Yii::t(\'app\', \'Open\') : Yii::t(\'app\', \'Close\')',
'filter' => array('0' => Yii::t('app', 'Open'), '1' => Yii::t('app', 'Close')),
'htmlOptions'=>array('width'=>'60px', 'style'=>'text-align:center'),
),
'remarks',
array(
'class' => 'CButtonColumn',
'visible'=>true,
'htmlOptions'=>array('width'=>'70px'),
'template' => '{view}{update}{delete}{changeComplete}',
'buttons'=>array(
'view' => array(
'visible'=>"true",
),
'update' => array(
'visible'=>"true",
),
'delete' => array(
'visible'=>"UserIdentity::isRoleMember('Admin')",
),
'changeComplete' => array(
'visible' => '$data->complete=="0"',
'imageUrl' => 'images/complete.png',
'options' => array(
'title' => 'Complete',
),
'url' => 'Yii::app()->createUrl("booking/changeComplete", array("id"=>$data->id))',
'click' => "function(){
$.fn.yiiGridView.update(\"booking-grid\", {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$.fn.yiiGridView.update(\"booking-grid\");
}
})
return false;
}",
),
),
),
))); ?>
I have tried looking at other CGridViews with the same field, they look the same and they're working perfectly fine.
I think the problem is $data->service. Probably your data has a relation with the Service entity. So for accessing attributes of Service you should use $data->service->attributeName.
I've got the below code which will not 'work'... How can I go about excluding multiple items from the SQL query? I've tried many different combinations without any luck :(
$this->autoLayout = false;
$this->set('songs', $this->CcFile->find('all', array(
'fields' => array(
'track_title',
'artist_name',
'lptime',
'id'
),
'conditions' => array(
'AND' => array(
'NOT' => array(
'artist_name' => 'Jam FM Bed',
),
'NOT' => array(
'artist_name' => 'Airtime Show Recorder',
),
'NOT' => array(
'artist_name' => 'Jam FM Jingles',
),
'NOT' => array(
'artist_name' => 'Kent Scout Jingles',
),
),
),
'order' => array(
'lptime' => 'desc nulls last',
'artist_name' => 'asc'
)
)));
Try that:
'NOT' => array(
'artist_name' => array(
'Jam FM Bed',
'Airtime Show Recorder',
// ...
)
)
or
'artist_name NOT IN' => array(
'Jam FM Bed',
'Airtime Show Recorder',
// ...
)
Try this
fixed code
$this->autoLayout = false;
$this->set('songs', $this->CcFile->find('all', array(
'fields' => array(
'track_title',
'artist_name',
'lptime',
'id'
),
'conditions' => array(
'NOT' => array(
'artist_name' => Array(
'Jam FM Bed',
'Airtime Show Recorder',
'Jam FM Jingles',
'Kent Scout Jingles')
),
),
'order' => array(
'lptime' => 'desc nulls last',
'artist_name' => 'asc'
)
)));
I want to add single radio button to gridview row by row at yii. I googling like this "yii single radio button into cgridview" but I can't get what I want.
This is my gridview
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'acc-recei-grid',
'dataProvider'=>$model->search_implementerlist(),
'filter'=>$model,
'columns'=>array(
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => 2,
'checkBoxHtmlOptions' => array(
'name' => 'implementers[]',
),
'value'=>'$data->id',
'checked'=>function($data, $row) use ($current_implementers){
return in_array($data->id, $current_implementers);
}
),
array(
'name'=>'lead_implementer',
'type'=>'raw',
'value' => 'CHtml::radioButtonList("lead_implementer","'. $lead_implementer .'",array($data->id), array("template" => "{input}", "style" => "width:20px!important", "separator"=>" "))',
),
'username',
),
)); ?>
How can I do?
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'acc-recei-grid',
'dataProvider'=>$model->search_implementerlist(),
'filter'=>$model,
'columns'=>array(
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => 2,
'checkBoxHtmlOptions' => array(
'name' => 'implementers[]',
),
'value'=>'$data->id',
'checked'=>function($data, $row) use ($current_implementers){
return in_array($data->id, $current_implementers);
}
),
array(
'name'=>'lead_implementer',
'type'=>'raw',
'value' => 'CHtml::radioButtonList("lead_implementer","'. $lead_implementer .'",array("$data->id"=>"$data->id"), array("template" => "{input}", "style" => "width:20px!important", "separator"=>" "))',
),
'username',
),
)); ?>
I want to reduce the number of fields returned by cakephp's find('all') but don't know if this is possible.
$this->Group->find('all', $params);
where $params
$params = array(
'conditions' => array(
'Group.featured' => 1,
),
'contain' => array(
'User',
'Class' => array(
'conditions' => array(
'Class.exp IS NOT NULL',
'Class.tb <20',
)
)
)
));
The problem is that my Class table has many columns that i don't need and that take a long time to load, so i would line to only select 5 fields.
Can this be done in Cakephp or am i better off writing a regular query?
something like
$params = array(
'conditions' => array(
'Group.featured' => 1,
),
'contain' => array(
'User',
'Class.a',
'Class.b',
'Class.exp',
'Class.tb',
'Class' => array(
'conditions' => array(
'Class.exp IS NOT NULL',
'Class.tb <20',
)
)
)
));
Thank you
That's what the fields parameter is for.
$params = array(
...
'contain' => array(
'Class' => array(
'conditions' => array(
'Class.exp IS NOT NULL',
'Class.tb <20',
),
'fields' => array('a', 'b')
)
)
);
In my project one of the model named types having multiple relation to other models the criteria with part is giving below its like
$criteria->with = array(
'category',
'subCategory',
'accountsSupplierPriceDetails' => array(
'with' => 'serviceLevel'
)
);
the relationship goes like
types - category - relation(1-1)
types - subcategory - relation(1-1)
types - accountsSupplierPriceDetails - relation(1-1)
accountsSupplierPriceDetails - serviceLevel - relation(1-n)
my problem is how to display the names from each table in a grid. the result of (1-n) should be displayed in a dropdownbox. when i try to access the data from column it shows the error Trying to get property of non-object ($data->accountsSupplierPriceDetails->serviceLevel ->name). can anyone please help me.
Thanks in advance.
in my view i create a cgridview with 5 rows in which one row data is populated using dropdownlist.
<div style="width:700px; height:auto;">
<?php
$widget = $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'response-grid',
'dataProvider' => $pickdataset->pickCategorylistingForMain(),
'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',
'summaryText' => '',
'ajaxUpdate' => 'response-grid',
'enablePagination' => true,
'pager' => array(
'class' => 'LinkPager',
'cssFile' => false,
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'columns' => array(
array(
'name' => 'id',
'header' => '#',
'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),
array(
'type' => 'raw',
'name' => 'categoryExt',
'header' => 'Category',
),
array(
'type' => 'raw',
'header' => 'Sub Category',
'value' => '$data->subCategory->name',
),
array(
'type' => 'raw',
'name' => 'locationExt',
'header' => 'Location',
),
array(
'type' => 'raw',
'header' => 'Name',
'value' => 'CHtml::dropDownList($data->corporate_id."-".$data->category_id."-".$data->sub_category_id."-".$data->location_id,"",popDropBox($data->masterCategoryServiceLevels), array("class" => "listbox"), array("empty" => "Select a Location"))',
),
array(
'type' => 'raw',
'header' => 'Pick',
'value' => 'CHtml::image(Yii::app()->baseUrl . "/media/images/edit_icon.png",$data->corporate_id."-".$data->category_id."-".$data->sub_category_id."-".$data->location_id,array("title" => "Select this Combination"))',
),
),));
function popDropBox($data)
{
$list = array();
foreach ($data as $row)
{
$list[$row->serviceLevel->id] = $row->serviceLevel->name;
}
return $list;
}
?>
</div>
the relation in model is:
'masterCategoryServiceLevels' => array(self::HAS_MANY, 'MasterCategoryServiceLevel', 'category_template_id'),
'corporate' => array(self::BELONGS_TO, 'AccountsCorporate', 'corporate_id'),
'category' => array(self::BELONGS_TO, 'MasterCategory', 'category_id'),
'subCategory' => array(self::BELONGS_TO, 'MasterCategory', 'sub_category_id'),
'location' => array(self::BELONGS_TO, 'MasterLocation', 'location_id'),
the row is
array(
'type' => 'raw',
'header' => 'Name',
'value' => 'CHtml::dropDownList($data->corporate_id."-".$data->category_id."-".$data->sub_category_id."-".$data->location_id,"",popDropBox($data->masterCategoryServiceLevels), array("class" => "listbox"), array("empty" => "Select a Location"))',
),
and i use a function to create dropdown data is
function popDropBox($data)
{
$list = array();
foreach ($data as $row)
{
$list[$row->serviceLevel->id] = $row->serviceLevel->name;
}
return $list;
}
please comment if you have any doubt. i am free to share... have a nice day SO friends... wishes and prayers.