Fetch All Rows From Authitem Whose Type Are 2

Hi,

I want to get all the rows from authitem whose type=‘2’.

I get

error when I try to fetch using the below code :




$model= AuthItem::model()->findAllByAttributes(array('type' => 2));

$this->render('index',array('model'=>$model));



Also tried using




 $model= Yii::app()->authManager->getRoles();

Please help me to get all the rows from authitem whose type=‘2’.

Thanks & Regards,

Vidhya

just write


$model= AuthAssignment::model()->find('type' => 2);

Try with replace [size="2"]findByAttributes[/size][size="2"] instead of findAllByAttributes… this also give all rows.[/size]

[size="2"]

[/size]

Hi Kiran Sharma,

I tried findbyattributes and it returns only one row.

Thanks & Regards,

Vidhya

Hi Ankit Modi,

I tried


$model= AuthItem::model()->find(array('type' => 2));

but it throws an exception stating that

Thanks & Regards,

Vidhya

Ohh yes, my mistake.

Check this forum post for findbyattributes.

If not working than Try FindAll.

[color="#000000"]findAll[/color][color="#666600"]([/color][color="#000000"]array[/color][color="#666600"]([/color][color="#008800"]‘order’[/color][color="#666600"]=>[/color][color="#008800"]‘somefield’[/color][color="#666600"],[/color] [color="#008800"]‘condition’[/color][color="#666600"]=>[/color][color="#008800"]‘otherfield=:x’[/color][color="#666600"],[/color] [color="#008800"]‘params’[/color][color="#666600"]=>[/color][color="#000000"]array[/color]color="#666600"));[/color]

[/size]

Hi Kiran Sharma,

I still get the same error. I tried both ways:

when I try the same code with other model itseems to be working fine. Why am I facing issue with this alone?

Kindly help me to figure out.

Thanks & Regards,

Vidhya

hi can you please post the AuthItem model? or check in table type filed is or not?

check this wiki

Hi Ankit Modi,

There is a field as "type" in authitem table.


<?php




class AuthItem extends CActiveRecord

{

	

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	

	public function tableName()

	{

		return 'authitem';

	}


	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('id, name, type, last_modified_user, date_last_modified, enabled', 'required'),

			array('type, enabled', 'numerical', 'integerOnly'=>true),

			array('name', 'length', 'max'=>64),

			array('last_modified_user', 'length', 'max'=>25),

			array('description, bizrule, data', 'safe'),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('name, type, description, bizrule, data, last_modified_user, date_last_modified, enabled', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'authassignments' => array(self::HAS_MANY, 'Authassignment', 'itemname'),

			'authitemchildren' => array(self::HAS_MANY, 'Authitemchild', 'parent'),

			'authitemchildren1' => array(self::HAS_MANY, 'Authitemchild', 'child'),

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

                    'id' => 'id',

			'name' => 'Name',

			'type' => 'Type',

			'description' => 'Description',

			'bizrule' => 'Bizrule',

			'data' => 'Data',

			'last_modified_user' => 'Last Modified User',

			'date_last_modified' => 'Date Last Modified',

			'enabled' => 'Enabled',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	........

}

Thanks & Regards,

Vidhya

Hi you can try this

if you want to fetch the all recored which type is 2


$data=AuthItem::model()->findAll("type='2'");

foreach ($data as $value){

    print_r($value->attributes);

}

Hi Ankit Modi,

I get the above error while using the below code:




 $model2=AuthItem::model()->findAll("type='2'");

 $this->render('index',array('model'=>$model2));



but am able to see the records using


$data=AuthItem::model()->findAll("type='2'");

foreach ($data as $value){

    print_r($value->attributes);



Can you please guide me on how to pass the values to view through render?

Thanks & Regards,

Vidhya

please see this

Try this




<?php 

$models= AuthItem::model()->findAllByAttributes(array('type'=>2));

foreach ($models as $re)

{

    echo $re->field_name."<br>";

}

?>



Hi Aneesh,

I want to pass the $models to view page using render method.

While doing so I get the error.

Thanks & Regards,

Vidhya

Whats the error?

You can pass variable like this ( from controller)


<?php 

$results= AuthItem::model()->findAllByAttributes(array('type'=>2));

$this->render('detail', array('results'=>$results));

?>

in view - access it as $results

Hi In your controller you can write a only query and pass the object on view file using render method.

for e.g

1) controller file…


<?php 

$model= AuthItem::model()->findAll("type=>'2'");

$this->render('index',array('model'=>$model));

?>

2) view file


<?php 

foreach ($model as $re)

{

    echo $re->field_name."<br>";

}

?>

Hi Ankit Modi,

Thank you for your reply.

Sorry for not being specific [I need to display in CgridView in view file]

Am able to fetch the values using forloop but how to display the values in a Cgridview.

Am receiving the error when I try to display in Cgridview

Thanks & Regards,

Vidhya

Hi Aneesh Asokan,

I am getting the below error when I try to display the values in Cgridview

Thanks & Regards,

Vidhya Prabha

Hi if you want to ceate a custom admin please see it