Hello, Im braziliam, sorry for my bad English, and Hi, it
s my first post.
Why I can`t use the follow code:
protected/components/Controller.php
public function init() {
pr(Yii::app()->configuracoes);
$this->_settings = Yii::app()->configuracoes->get();
}
I get the follow error:
Configuracoes and its behaviors do not have a method or closure named "app".
Adittionaly, from my configuration file:
protected/config/main.php
[...]
'components'=>array(
'configuracoes' => array(
'class' => 'Configuracoes',
),
[...]
What`s wrong?
Thanks!
gusnips
(Gustavo)
2
Hello Gabriel, and welcome to the forum!
In your class "configuracoes" you trying to call the method "app"
$this->app();
somewhere, which doesn’t exist, I guess you are actually trying to call Yii::app()
Gustavo
Hi, and thanks,
I have the follow code, from top of the Configuracoes.php component:
class Configuracoes extends CApplicationComponent {
[...]
public function init() {
$this->_preload();
}
[...]
protected function _preload() {
[...]
}
EDIT
oHH, inside _preload method I have found:
$db = $this->app()->getDb();
and the correct code are
$db = Yii::app()->getDb();
Problem solved, thanks Gustavo.
Tip:
never call $this->app() (only if it is a mistake =P). Ever call Yii::app(), everywhere.