[ask]index error

hi, all. i want to ask :

i have a table name tbl_packet with 1 field in it name status. in status i save a value with null,0,or 1.

and i want to show the status with word not number.

so i have a function like this:


public function getStatusPacket($id)

{

	if($id == null )

		$status = 'New';

	else if($id == 0)

		$status = 'Not Approved';

	else if($id == 1)

		$status = 'Approved';

	return $status;

}

and i have a code like this in protected/view/packet/admin.php like this :


<?php 

	$session = new ChttpSession;

	$session->open();

	

	$columns[]=array(

		'name' =>'name',

		'type'=>'raw',

		'value'=>'CHtml::link($data->packet_name,array("packet/view","id"=>$data->id))',

	);

	

	$columns[]=array(

		'name'=>'packet_name',

		'value'=>'$data->packet_name',

	);

	

	$columns[]=array(

		'name'=>'packet_price',

		'value'=>'$data->packet_price',

	);

	

	$columns[]=array(

		'name'=>'packet_unit',

		'value'=>'$data->packet_unit',

	);

	

	$columns[]=array(

		'name'=>'status',

		[u]'value'=>'Controller::getStatusPacket($data->status)'[/u], //get the word from it function in Controller.php

	);

	

	if($session['id'] != "")

	{

		if(Yii::app()->user->isAdmin())

		{

			$columns[]=array(

				'header'=>'Action',

				'class'=>'CButtonColumn',

			);

		}

		else

		{

			$columns[]=array(

				'header'=>'Action',

				'class'=>'CButtonColumn',

				'template'=>'{view}',

				'buttons'=>array(

					'view'=>array(

						'label'=>'view',

						'url'=>'Yii::app()->createUrl("Packet/view",array("id"=>$data->id))',

					),

				),

				

			);

		}

	}

	

	$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'packet-grid',

	'dataProvider'=>$model->search(),

	'columns'=>$columns,

)); ?>

if i put the getStatusPacket function in controller, and in the admin.php i use Controller::getStatusPacket , its not working, it show error like this

1872

untitled.JPG

if i run it in another computer it works,can someone help me?

In the view $this refers to the current controller… that in turn is extended from Controller.php… so it’s the same if you put that function in the current controller or in Controller.php

you have to use


$this->getStatusPacket(...);


public static function getStatusPacket($id=null)

{

  switch($id){

    case null: return 'New';

    case 0: return 'Not Approved';

    case 1: return 'Approved';

    default: throw new CException('Status '.$id.' not defined');

  }

}

EDIT: or just do like mdomba said, so you doesn’t need to change the method

Fast reply Maurizio ;)

[quote=“Gustavo, post:3, topic:41526”]


public static function getStatusPacket($id=null)

{

  switch($id){

    case null: return 'New';

    case 0: return 'Not Approved';

    case 1: return 'Approved';

    default: throw new CException('Status '.$id.' not defined');

  }

}

thanks it works now ^^