C5-8.2.1: Why string doesn't get set with value?
Permalink
[UPDATED]
If I declare a string in a class and set its value right there, everything works.
But if I only declare a string in a class, but set its value in the view(), the value doesn't get set, it returns empty strings. Why?
This works:
This does not:
How can I set variables in the controller so that they can be both used in the view.php and also get translated? The t() function obviously doesn't work on variable declarations in a class.
Thank you.
If I declare a string in a class and set its value right there, everything works.
But if I only declare a string in a class, but set its value in the view(), the value doesn't get set, it returns empty strings. Why?
This works:
class Controller extends BlockController { public $name = 'Name'; public function view() { $this->validate(); } public validate() { $this->set('name', $this->name); } }
This does not:
class Controller extends BlockController { public $name = ''; public function view() { $this->name = t('Name'); $this->validate(); } public validate() { $this->set('name', $this->name); } }
How can I set variables in the controller so that they can be both used in the view.php and also get translated? The t() function obviously doesn't work on variable declarations in a class.
Thank you.
You need to do it like this
Hi.
Sorry, I made a mistake when I was writing it for the post. I've updated the original code above.
Sorry, I made a mistake when I was writing it for the post. I've updated the original code above.
I also tried setting the property in a constructor - still an empty string returns.
The dilemma is I can either set public string properties in the class but how can I have them translated? Or I can use local variables in the view() - this works fine, but I can't use them throughout other methods.
How can I set public string properties and have them picked up by the t()?
The dilemma is I can either set public string properties in the class but how can I have them translated? Or I can use local variables in the view() - this works fine, but I can't use them throughout other methods.
How can I set public string properties and have them picked up by the t()?
Ok, I got it. I had to put my property assignments in the on_start() and that's it, it all works now.