unexpected T_PAAMAYIM_NEKUDOTAYIM

Hi alls, i still newbie & want to ask question. i create a function in Controller.php like this :


public function aftersave($tanda,$id,$set=false,$data='')

  {

        $connection = Yii::app()->db;

	$tabel = $this->tablename($tanda);

	$nama = $this->projectname($tanda);

	[color="#FF0000"]$current = $nama::model()->findByPk($id);[/color]

  }


public function projectname($flags)

	{

		if($flags == "1")

		{

			$nama = "MediaSeller";

		}

		else if($flags == 2)

		{

			$nama = "ProductCategory";

		}

		else if($flags == 3)

		{

			$nama = "Advertiser";

		}

		

		return $nama;

	}

	

	function tablename($flags)

	{

		if($flags == 1)

		{

			$tabel = "tbl_media_seller";

		}

		else if($flags == 2)

		{

			$tabel = "tbl_product_category";

		}

		else if($flags == 3)

		{

			$tabel = "tbl_advertiser";

		}

		

		return $tabel;

	}

and add coding in actionCreate() in MediaSellerController.php like this :


public function actionCreate()

	{

		$model=new MediaSeller;


		if(isset($_POST['MediaSeller']))

		{

			$model->attributes = $_POST['MediaSeller'];

			$row = Controller::kueri(1,$model);

			if ($row == null)

			{

				if ($model->save())

				{	

					$last = Yii::app()->db->getLastInsertID();

					Controller::aftersave(1,$last);

					$this->redirect(array('view','id'=>$model->id));

				}

			}

			else

			{

				Controller::aftersave(1,$row,true,$_POST['MediaSeller']);

				$this->redirect(array('view','id'=>$row));

			}	

		}

		

		$this->render('create',array(

			'model'=>$model,

		));

	}



and if i run in my localhost using php version 5.3 it’s work, but if i run in my server with php version 5.2 it said Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in Controller.php on line $current = $nama::model()->findByPk($id); in function aftersave

can someone help? thanks

$current = $nama::model()->findByPk($id);

That error mean that you have extra double colon: http://stackoverflow.com/questions/592322/php-expects-t-paamayim-nekudotayim

So, one of the solution is to create object of desired class:


if($flags == "1")

                {

                        $nama = "MediaSeller";

                }

                else if($flags == 2)

                {

                        $nama = "ProductCategory";

                }

                else if($flags == 3)

                {

                        $nama = "Advertiser";

                }

$ret_class =  new $nama;                




And then call findByPk method on object, not on class.

Another solution would be using eval() function.

I think it is possible only in PHP 5.3+, in previous versions you should use:




$current = CActiveRecord::model($nama)->findByPk($id);



T_PAAMAYIM_NEKUDOTAYIM is php it is problem in your dynamic static class


$class::model()->find() 

solutions


$model = new $class;

$model->find();

Or




$model = call_user_func(array($nama, 'model'));

$current = $model->findByPk($id);




$model = call_user_func(array($nama, 'model'));

$current = $model->findByPk($id);

thanks all for the help, i use this code and it’s work ^^