roopeshpdit
(Roopeshreddy S)
February 16, 2011, 3:42am
1
If i am getting id from the page
http://localhost/edusoft/index.php?r=patientinfo/update&id=1
Where id=1
and patientinfo/update page has a widget
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'visit-info-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'Patient_ID',
'Date_of_Visit',
'Duration_of_Visit_in_Hours',
'Educator',
'Type_of_Visit',
/*
'Class',
'Notes',
'Eye_Checkup_Info',
'Lab_HbA1c',
'Pt_stated_HbA1c',
'Date_Drawn',
'HbaIc_Is_Not_know',
*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
How can pass id=1 from the page link to the widget so that the widget displays only id=1 and not all the records
jkofsky
(Jkofsky)
February 16, 2011, 6:59am
2
If i am getting id from the page
http://localhost/edusoft/index.php?r=patientinfo/update&id=1
Where id=1
and patientinfo/update page has a widget
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'visit-info-grid',
<snip>
How can pass id=1 from the page link to the widget so that the widget displays only id=1 and not all the records
First a question: Why would you have a CGridView on an Update page? Update should be the form for editing.
That aside: If it is actually on the admin.php page, take a look at how the search/filter routine(s) that are generated in the gii CRUD operations. Using the search at the top of the grid will limit the displayed information to just what meets the conditions.
hi,
you can pass id like that :
$dataprovider=new CActiveDataProvider('Model', array(
'criteria'=>array(
'condition'=>'id_model=:id',
'params'=>array('id'=>$_GET['id']),
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'visit-info-grid',
'dataProvider'=>$dataprovider
'filter'=>$model,
'columns'=>array(
'id',
'Patient_ID',
'Date_of_Visit',
'Duration_of_Visit_in_Hours',
'Educator',
'Type_of_Visit',
/*
'Class',
'Notes',
'Eye_Checkup_Info',
'Lab_HbA1c',
'Pt_stated_HbA1c',
'Date_Drawn',
'HbaIc_Is_Not_know',
*/
array(
'class'=>'CButtonColumn',
),
),
));
see Dataprovider documentation for mode details.
Note that this is not the optimal way to do that, you must put the
$dataprovider=new CActiveDataProvider('Model', array(
'criteria'=>array(
'condition'=>'id_model=:id',
'params'=>array('id'=>$_GET['id']),
),
));
in controller to respect the MVC pattern that yii work with it
roopeshpdit
(Roopeshreddy S)
February 16, 2011, 11:05am
4
hi,
you can pass id like that :
$dataprovider=new CActiveDataProvider('Model', array(
'criteria'=>array(
'condition'=>'id_model=:id',
'params'=>array('id'=>$_GET['id']),
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'visit-info-grid',
'dataProvider'=>$dataprovider
'filter'=>$model,
'columns'=>array(
'id',
'Patient_ID',
'Date_of_Visit',
'Duration_of_Visit_in_Hours',
'Educator',
'Type_of_Visit',
/*
'Class',
'Notes',
'Eye_Checkup_Info',
'Lab_HbA1c',
'Pt_stated_HbA1c',
'Date_Drawn',
'HbaIc_Is_Not_know',
*/
array(
'class'=>'CButtonColumn',
),
),
));
see Dataprovider documentation for mode details.
Note that this is not the optimal way to do that, you must put the
$dataprovider=new CActiveDataProvider('Model', array(
'criteria'=>array(
'condition'=>'id_model=:id',
'params'=>array('id'=>$_GET['id']),
),
));
in controller to respect the MVC pattern that yii work with it
I get this error after i add the above code
include(model.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
C:\wamp\www\yii-install\framework\YiiBase.php(395)
383 * @return boolean whether the class has been loaded successfully
384 */
385 public static function autoload($className)
386 {
387 // use include so that the error PHP file may appear
388 if(isset(self::$_coreClasses[$className]))
389 include(YII_PATH.self::$_coreClasses[$className]);
390 else if(isset(self::$classMap[$className]))
391 include(self::$classMap[$className]);
392 else
393 {
394 if(strpos($className,'\\')===false)
395 include($className.'.php');
396 else // class name with namespace in PHP 5.3
397 {
398 $namespace=str_replace('\\','.',ltrim($className,'\\'));
399 if(($path=self::getPathOfAlias($namespace))!==false)
400 include($path.'.php');
401 else
402 return false;
403 }
404 return class_exists($className,false) || interface_exists($className,false);
405 }
406 return true;
407 }
Stack Trace
#0
+ C:\wamp\www\yii-install\framework\YiiBase.php(395): YiiBase::autoload()
#1
unknown(0): YiiBase::autoload("model")
#2
+ C:\wamp\www\yii-install\framework\db\ar\CActiveRecord.php(352): spl_autoload_call("model")
#3
+ C:\wamp\www\yii-install\framework\web\CActiveDataProvider.php(63): CActiveRecord::model("model")
#4
– C:\wamp\www\edusoft\protected\views\visitInfo\create.php(24): CActiveDataProvider->__construct("model", array(array("id_model=:id", array("2"))))
19 $dataprovider=new CActiveDataProvider('model', array(
20 'criteria'=>array(
21 'condition'=>'id_model=:id',
22 'params'=>array('id'=>$_GET['id']),
23 ),
24 ));
25
26
27 $this->widget('zii.widgets.grid.CGridView', array(
28 'id'=>'visit-info-grid',
29 'dataProvider'=>$dataProvider,
#5
+ C:\wamp\www\yii-install\framework\web\CBaseController.php(119): require("C:\wamp\www\edusoft\protected\views\visitInfo\create.php")
#6
+ C:\wamp\www\yii-install\framework\web\CBaseController.php(88): CBaseController->renderInternal("C:\wamp\www\edusoft\protected\views/visitinfo\create.php", array(VisitInfo), true)
#7
+ C:\wamp\www\yii-install\framework\web\CController.php(833): CBaseController->renderFile("C:\wamp\www\edusoft\protected\views/visitinfo\create.php", array(VisitInfo), true)
#8
+ C:\wamp\www\yii-install\framework\web\CController.php(746): CController->renderPartial("create", array(VisitInfo), true)
#9
– C:\wamp\www\edusoft\protected\controllers\VisitInfoController.php(106): CController->render("create", array(VisitInfo))
101 $this->redirect(array('view','id'=>$model->id));
102 }
103
104 $this->render('create',array(
105 'model'=>$model,
106 ));
107 }
108
109 /**
110 * Updates a particular model.
111 * If update is successful, the browser will be redirected to the 'view' page.
#10
+ C:\wamp\www\yii-install\framework\web\actions\CInlineAction.php(57): VisitInfoController->actionCreate()
#11
+ C:\wamp\www\yii-install\framework\web\CController.php(300): CInlineAction->run()
#12
+ C:\wamp\www\yii-install\framework\web\filters\CFilterChain.php(133): CController->runAction(CInlineAction)
#13
+ C:\wamp\www\yii-install\framework\web\filters\CFilter.php(41): CFilterChain->run()
#14
+ C:\wamp\www\yii-install\framework\web\CController.php(1088): CFilter->filter(CFilterChain)
#15
+ C:\wamp\www\yii-install\framework\web\filters\CInlineFilter.php(59): CController->filterAccessControl(CFilterChain)
#16
+ C:\wamp\www\yii-install\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(CFilterChain)
#17
+ C:\wamp\www\yii-install\framework\web\CController.php(283): CFilterChain->run()
#18
+ C:\wamp\www\yii-install\framework\web\CController.php(257): CController->runActionWithFilters(CInlineAction, array("accessControl"))
#19
+ C:\wamp\www\yii-install\framework\web\CWebApplication.php(328): CController->run("create")
#20
+ C:\wamp\www\yii-install\framework\web\CWebApplication.php(121): CWebApplication->runController("visitinfo/create")
#21
+ C:\wamp\www\yii-install\framework\base\CApplication.php(155): CWebApplication->processRequest()
#22
– C:\wamp\www\edusoft\index.php(13): CApplication->run()
08 defined('YII_DEBUG') or define('YII_DEBUG',true);
09 // specify how many levels of call stack should be shown in each log message
10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
11
12 require_once($yii);
13 Yii::createWebApplication($config)->run();
Please let me know if i missed some thing?
$dataprovider=new CActiveDataProvider('Model', array(...
yes you miss something
i mean by ‘Model’ your model that is generated, i think in your case it’s “Patientinfo”
so i think you must do like that :
$dataprovider=new CActiveDataProvider('Patientinfo', array(
'criteria'=>array(
'condition'=>'id=:id',
'params'=>array('id'=>$_GET['id']),
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'visit-info-grid',
'dataProvider'=>$dataprovider
'filter'=>$model,
'columns'=>array(
'id',
'Patient_ID',
'Date_of_Visit',
'Duration_of_Visit_in_Hours',
'Educator',
'Type_of_Visit',
/*
'Class',
'Notes',
'Eye_Checkup_Info',
'Lab_HbA1c',
'Pt_stated_HbA1c',
'Date_Drawn',
'HbaIc_Is_Not_know',
*/
array(
'class'=>'CButtonColumn',
),
),
));
roopeshpdit
(Roopeshreddy S)
February 16, 2011, 4:12pm
6
$dataprovider=new CActiveDataProvider('Model', array(...
yes you miss something
i mean by ‘Model’ your model that is generated, i think in your case it’s “Patientinfo”
so i think you must do like that :
$dataprovider=new CActiveDataProvider('Patientinfo', array(
'criteria'=>array(
'condition'=>'id=:id',
'params'=>array('id'=>$_GET['id']),
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'visit-info-grid',
'dataProvider'=>$dataprovider
'filter'=>$model,
'columns'=>array(
'id',
'Patient_ID',
'Date_of_Visit',
'Duration_of_Visit_in_Hours',
'Educator',
'Type_of_Visit',
/*
'Class',
'Notes',
'Eye_Checkup_Info',
'Lab_HbA1c',
'Pt_stated_HbA1c',
'Date_Drawn',
'HbaIc_Is_Not_know',
*/
array(
'class'=>'CButtonColumn',
),
),
));
I am sorry for asking you silly question, but i changed the model to patientinfo this is what i am getting
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id_model' in 'where clause'
and if i comment the condition
'criteria'=>array(
//'condition'=>'id=:id',
'params'=>array('id'=>$_GET['id']),
i get an error
Property "PatientInfo.id" is not defined.
jkofsky
(Jkofsky)
February 16, 2011, 6:36pm
7
…
and if i comment the condition
'criteria'=>array(
//'condition'=>'id=:id',
'params'=>array('id'=>$_GET['id']),
i get an error
Property "PatientInfo.id" is not defined.
I think you need to add a ‘:’ in front of id like this,
'params'=>array(':id'=>$_GET['id']),
roopeshpdit
(Roopeshreddy S)
February 16, 2011, 8:05pm
8
Thank You Very much for the help it works perfect
jkofsky
(Jkofsky)
February 16, 2011, 8:35pm
9
Glad to hear it, sometimes even us newbies get lucky