Yii Framework Forum: use condition - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

use condition Rate Topic: -----

#1 User is offline   neel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 08-October 09

Posted 19 January 2010 - 08:33 AM

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?
0

#2 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 19 January 2010 - 09:32 AM

see this http://www.yiiframew...iveDataProvider
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
0

#3 User is offline   neel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 08-October 09

Posted 19 January 2010 - 03:01 PM

View PostHoracio 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?
0

#4 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

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/
0

#5 User is offline   neel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 08-October 09

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
0

#6 User is offline   gallego123 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 20 January 2010 - 05:57 AM

View PostNeel, 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


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/
0

#7 User is offline   Daniel M 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 19-January 10
  • Location:Germany, Saarland

Posted 20 January 2010 - 06:36 AM

View PostHoracio 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


This should not matter.

View PostNeel, 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


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!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users