Friday, July 26, 2019

php - Yii custom Widget, loader error



Please, help me with this problem (I am using Yii, Xampp on a Windows localhost):



So... I've created a new widget in "protected\components\views\Magus.php".




    class Magus extends CWidget {

//////////////////////////////
public function run()
{
echo '

Trallala :) !

'; // do something.
}
//////////////////////////////


} //end class


It's used here ("protected/views/layouts/main.php"):



    $this->widget('/views/Magus');
?>



And this causes a loader (?) error:



Fatal error: include() [function.include]: 
Cannot redeclare class magus in C:\xampp\htdocs\yii\framework\YiiBase.php on line 421


But the error doesn't happen, if the widget file is placed directly in "protected\components". What is the reason of that error and how to correct it ? Thank you in advance !


Answer



You use wrong paths.
I suggest you to put your widget php file into protected/components/Magus.php and then you can call it from view with




$this->widget('application.components.Magus');


Or you can keep it in folder where you have it and call it like this:



$this->widget('application.components.views.Magus');

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...