Error using Yii::app()->theme->baseUrl in class extending CButtonColumn

I have the following class so that I can customize my button column for admin actions:


class ButtonColumn extends CButtonColumn {

	public $template = '{update} {delete}';

	public $buttons= array(

		'update'=>array(

			'label'=>'Update',

			'imageUrl'=>Yii::app()->theme->baseUrl . '/images/icons/edit.png',

		),

		'delete'=>array(

			'label'=>'Delete',

			'imageUrl'=>Yii::app()->theme->baseUrl . '/images/icons/delete.png',

		),

	 );

}

With that class being used, I receive the error “Parse error: syntax error, unexpected ‘(’, expecting ‘)’.” If I take the “imageUrl” out of this class and place it within the CGridView as “updateButtonImageUrl” it works as expected. For obvious reasons, I don’t want to include that in all of my admin actions, I just want them all to have the update and delete buttons with my new icons.

Why can I not seem to use “Yii::app()->theme->baseUrl” within a class? I know this is my newbie showing through because this must be a concept that I have not yet learned. Can someone please point me in the right direction? Google and the Yii forums haven’t shown me the answer I’m looking for just yet. Thank you!

its


Yii::app()->request->baseUrl

not


Yii::app()->theme->baseUrl

That does not work either. I am using "theme" instead of "request" because of a global theme I have implemented across the site.

Hi JustinV,

Can tell us what Yii::app()->theme->baseUr return in your CButton class ?

can you do a vardump without using imageurl ?

thx

If I toss that onto the view.php page, I get ‘string(24) “/themes/admin-chromatron”’ so it seems to work there as well. Like I mentioned earlier, I can set the correct image within CGridView using ‘updateButtonImageUrl’ but when I try to make the exact same line of code work within my class, it doesn’t work.

Do you not have access to Yii::app() within a class? Or do you have access to it but need to reference it differently? The way php is complaining about an unexpected opening parenthesis makes me wonder what I need to be using other than app().

Hi JustinV,

After some investigation i think the probleme not came from yii but it’s the normal

behavior of oop in php language, i am not an expert in the subject and i want to know

more about it if there are some oop expert reading this thread, so it seems that you can’t

init button property with a class variable,

There are a solution but … it’s apt to you

using the int method of CButtonColumn




public function init()

	{

		$this->buttons= array(

                  'update'=>array(

                        'label'=>'Update',

                        'imageUrl'=>Yii::app()->request->baseUrl."/images/icons/edit.png",

                  ),

                  'delete'=>array(

                        'label'=>'Delete',

                        'imageUrl'=>Yii::app()->request->baseUrl . '/images/icons/delete.png',

                  ),

		);

		parent::init();

	}



hope this code can help you.