using a variable to represent a class? Can anyone help

#1
[eluser]prestondocks[/eluser]
Hi, Can anyone enlighten me on how to set a property in a class, where the class name is held in a variable.

I am trying to set a class property based on the value of class name in $this->router->class. I have tried $this->router->class::view_data['site_name'] = 'xyz' but as I expected I get a php error

The exact error being
Code:
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in C:\xampp\htdocs\intranet\system\application\modules\site\models\site_model.php on line 7

Can anyone help me out.

Thanks
Simon

#2
[eluser]WanWizard[/eluser]
How about
Code:
$class = $this->router->class;
$this->$class->property = 'xyz';

#3
[eluser]megablue[/eluser]
[quote author="WanWizard" date="1281926442"]How about
Code:
$class = $this->router->class;
$this->$class->property = 'xyz';
[/quote]

I'm using this way as well. You can not call an object or method dynamically by using an object or class statement. It will confuse the parser.

#4
[eluser]prestondocks[/eluser]
Thanks for your input. I have not tried this solution yet, but will put it in my tool box and sure it will come in handy at some point.

I listened to the Codeigniter podcast last night issue 3. They were talking about sub classing and I realised this was the best way to go. I will create a sub class that extends controller which will contain the variable and I will make all my controllers extend this sub class.

This will give all my controllers access to that variable and will open up a lot of other options for sharing common data within my application. Hoping it will allow me reduce my code in regards to security and theming.

Thanks


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.