Is it possible to have nested CGridViews?
#1
Posted 27 June 2012 - 12:16 AM
However I was wondering if there were any solutions to show the related comments shown underneath its post in some sort of nested view.
Is something like this possible? I've seen this post (http://stackoverflow...ested-cgridview) but I am looking to actually include CGridView nested.
#2
Posted 27 June 2012 - 06:48 AM
when i answer, if my answer does not make sense, don't blame on me, coz i am trying to answer to be answered;
ok, i'm covered to mess up and fooling around, yeehaw ...
#3
Posted 27 June 2012 - 01:07 PM
dubby, on 27 June 2012 - 12:16 AM, said:
However I was wondering if there were any solutions to show the related comments shown underneath its post in some sort of nested view.
Is something like this possible? I've seen this post (http://stackoverflow...ested-cgridview) but I am looking to actually include CGridView nested.
Hi Dubby,
I am new to Yii and am trying to do what you said was easy in the first part of your post. Can you please guide me how to do this? I have a department with many employees and I want to have a cgrid view of the employees when I click on a row in cgrid view of department. Thanks
#4
Posted 27 June 2012 - 01:27 PM
Bianca, on 27 June 2012 - 01:07 PM, said:
I am new to Yii and am trying to do what you said was easy in the first part of your post. Can you please guide me how to do this? I have a department with many employees and I want to have a cgrid view of the employees when I click on a row in cgrid view of department. Thanks
Are talking about a CGridView of the departments, or of all employees? If just a department list, you can set the value of the column to a link to Employees with the selected department to view just those employees.
If a list of all Employees, then you could set up a dropdown list filter for the department column.
#5
Posted 27 June 2012 - 07:07 PM
That extensions looks good but it's not nested as such and it only includes the one model. I think I'll write the HTML out in a for loop to achieve what I need.
Bianca, you want something like this:
<?php $this->widget('zii.widgets.grid.CGridView',
array('dataProvider' => $dataProvider,
'columns'=>array(
'id',
'departmentName',
array('name'=>'Employees', 'type'=>'raw', 'value'=>'CHtml::link("Employees", array("employees/admin", "id"=>$data["id"]))'),
),
));
?>
and then in your Employee::actionAdmin method you could have something similar to this:
public function actionAdmin($id=null)
{
$model=new Employee('search');
$model->unsetAttributes(); // clear any default values
if($id != null)
$model->departmentId=$id;
$this->render('admin',array(
'model'=>$model,
));
}
Also, rather than specifying $id=null in the function declaration you could use a filter
#6
Posted 27 June 2012 - 08:16 PM
#7
Posted 28 June 2012 - 12:41 AM
dubby, on 27 June 2012 - 07:07 PM, said:
That extensions looks good but it's not nested as such and it only includes the one model. I think I'll write the HTML out in a for loop to achieve what I need.
Bianca, you want something like this:
<?php $this->widget('zii.widgets.grid.CGridView',
array('dataProvider' => $dataProvider,
'columns'=>array(
'id',
'departmentName',
array('name'=>'Employees', 'type'=>'raw', 'value'=>'CHtml::link("Employees", array("employees/admin", "id"=>$data["id"]))'),
),
));
?>
and then in your Employee::actionAdmin method you could have something similar to this:
public function actionAdmin($id=null)
{
$model=new Employee('search');
$model->unsetAttributes(); // clear any default values
if($id != null)
$model->departmentId=$id;
$this->render('admin',array(
'model'=>$model,
));
}
Also, rather than specifying $id=null in the function declaration you could use a filter
Thank you very much for your prompt reply. I tried it and had to do some modifications because of the double quotes (btw is it normal? I had to replace the double quotes by single ones) Where must you define variable $dataProvider? Sorry I am new at Yii and am finding it hard to understand. Glad if you could help me. Thanks
#8
Posted 28 June 2012 - 12:56 AM
Thanks
#9
Posted 28 June 2012 - 01:08 AM
#10
Posted 28 June 2012 - 02:54 AM
dubby, on 28 June 2012 - 01:08 AM, said:
Thanks Dubby. I looked for the explanation and found it but am unable to make it work: I have a problem with the syntax:
<?php $dataProvider=new CActiveDataProvider('Department'); ?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'department-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'name',
array('name'=>'Employees', 'type'=>'raw', 'value'=>'CHtml::link('Eyees', $this->createUrl('employee/admin'),array('id'=>'$data->id'))'),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
I am having a parse error:
Parse error: parse error, expecting `')'' in C:\wamp\www\testdrive\protected\views\department\admin.php on line 46
I have tried to edit several times but am stuck. Line 46 refers to CHtml::link
#11
Posted 28 June 2012 - 07:37 AM
Your issue is that you're encapsulating the string in single quotes but then having the variables also in single quotes. PHP is unable to determine where your string starts and stops.
Your example:
'CHtml::link('Eyees', $this->createUrl('employee/admin'),array('id'=>'$data->id'))'
try leaving the full string in single quotes but putting the variables in double quotes like this:
'CHtml::link("Eyees", $this->createUrl("employee/admin"),array("id"=>"$data->id"))'
Notice the single quotes appear as the very first and very last characters ONLY.
Further note: If you need to use single quotes (or only double quotes) throughout you need to escape them first like this:
'CHtml::link(\'Eyees\', $this->createUrl(\'employee/admin\'),array(\'id\'=>\'$data->id\'))'
#12
Posted 28 June 2012 - 07:38 AM
#13
Posted 10 July 2012 - 11:24 AM
I think this wiki is what you want:
http://www.yiiframew...ew-was-clicked/
Regards
Gerhard

Help















