I am trying to make $app
available for the whole class.
First, I get:
"Expression is not allowed as field default value"
Second, on line 5, I get:
Unidentified variable $app
How can I achieve my goal?
class UserController extends XController { var $app = Yii::app();; public function init() { $test = $app;
Default field values automatically insert the value of a custom field when a new record is created. You can use a default value on a formula for some types of fields or exact values, such as Checked or Unchecked for checkbox fields. After you have defined default values: The user chooses to create a new record.
You can not call a method to set a default value for a variable in PHP, not even if it is a static method. Change it to be set in the constructor:
use Yii; class UserController extends XController { var $app; function __construct() { $this->app = Yii::app(); } public function init() { $test = $this->app; } }
As a side note, you should not use the var
keyword in PHP versions > 4, see this question for an explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With