Widget Creation Error

Hi all,

I have created a widget with the following code:


class DUserOverview extends CWidget


	public $companyID;

	public $_data;


	 * Renders the detail view.

	 * This is the main entry of the whole detail view rendering.


	public function run()


		$_data = Users::model()->find('company='.$companyID);


			echo $_data->ID;


			echo "nope";




When I try to use the widget with the following code:

<?php $this->widget('DUserOverview', array(


)); ?>

I get the error: Undefined variable: companyID

even though I have set the variable above…

Any ideas would be great!



To access properties inside a class you need to use $this

so in your example inside run() it would be


Thanks for the reply, unfortunately, I now have the line:

$_data = Users::model()->find('company='.$this->$companyID);

which gives the error: Undefined variable: companyID

The same applies if I try to access $_data by going $this->$_data




Bah! Idiot reading abilities :) Thanks for the help/slap!!

Also, Isn’t it better to pass as a param?

$_data = Users::model()->find(‘company=:companyID’, array(’:companyID’ => $this->$companyID));

Only if it’s coming from “outside” (e.g. GET/POST parameter). If the value is generated in your code, parameter binding only adds unnecessary overhead.