Hello,
I upgrade Yii 1.0 to Yii 1.1, but I don't understand how to use condition in view file. Here is my view file
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'class'=>'CButtonColumn',
),
'name',
'address',
'phone',
'email',
),
)); ?>
I want to use this condition
<?php if ($model->User_id == Yii::app()->user->id){ ?>
Can anyone help me?
Page 1 of 1
use condition
#2
Posted 19 January 2010 - 09:32 AM
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
#3
Posted 19 January 2010 - 03:01 PM
Horacio Segura, on 19 January 2010 - 09:32 AM, said:
public function actionAdmin()
{
$dataProvider=new CActiveDataProvider('table1', array(
'criteria'=>array(
'condition'=>'a_id = 1 AND User_id = ?',
),
'pagination'=>array(
'pageSize'=>20,
),
));
$this->render('admin',array(
'dataProvider'=>$dataProvider,
));
}
How to use $model->User_id == Yii::app()->user->id) in the condition?
#4
Posted 19 January 2010 - 03:27 PM
public function actionAdmin()
{
$dataProvider=new CActiveDataProvider('table1', array(
'criteria'=>array(
'condition'=>'a_id = 1 AND User_id = '.Yii::app()->user->id ,
),
'pagination'=>array(
'pageSize'=>20,
),
));
$this->render('admin',array(
'dataProvider'=>$dataProvider,
));
}
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
#5
Posted 19 January 2010 - 06:34 PM
I got this error
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
#6
Posted 20 January 2010 - 05:57 AM
Neel, on 19 January 2010 - 06:34 PM, said:
I got this error
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
in my case: Yii::app()->user->id is a string
maybe you should use
Yii::app()->user->getState('User_id') and in the class UserIdentity, set this state
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
#7
Posted 20 January 2010 - 06:36 AM
Horacio Segura, on 20 January 2010 - 05:57 AM, said:
in my case: Yii::app()->user->id is a string
maybe you should use
Yii::app()->user->getState('User_id') and in the class UserIdentity, set this state
maybe you should use
Yii::app()->user->getState('User_id') and in the class UserIdentity, set this state
This should not matter.
Neel, on 19 January 2010 - 06:34 PM, said:
I got this error
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Your error looks like your Yii::app()->user->id contains no value which causes a broken condition clause.
In fact, if the user is not authenticated, Yii::app()->user->id defaults to NULL.
Either, check if your user is NULL before inserting it into your condition, or use (int)Yii::app()->user->id to guarantee an integer value (NULL will be 0).
Utinam ea res tibi usui fuerit!
Share this topic:
Page 1 of 1

Help












