1

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".

 <?php
   class Magus extends CWidget {

   //////////////////////////////
  public function run()
  {
    echo '<p style="color:blue; ">Trallala :) !</p>'; // do something.
  }
    //////////////////////////////

 } //end class

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

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

And this causes a loader (?) error:

Fatal error: include() [<a href='function.include'>function.include</a>]: 
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 !

4

1 回答 1

5

你使用了错误的路径。我建议你把你的小部件 php 文件放入protected/components/Magus.php,然后你可以从视图中调用它

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

或者您可以将其保存在您拥有它的文件夹中并像这样调用它:

$this->widget('application.components.views.Magus');
于 2011-09-15T18:46:38.680 回答