简体   繁体   English

Yii自定义小部件,加载程序错误

[英]Yii custom Widget, loader error

Please, help me with this problem (I am using Yii, Xampp on a Windows localhost): 请帮我解决这个问题(我在Windows本地主机上使用Yii,Xampp):

So... I've created a new widget in "protected\\components\\views\\Magus.php". 所以...我在“ 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"): 在这里使用(“ 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". 但是,如果将窗口小部件文件直接放置在“ protected \\ components”中,则不会发生该错误。 What is the reason of that error and how to correct it ? 该错误的原因是什么以及如何纠正它? Thank you in advance ! 先感谢您 !

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 我建议您将小部件php文件放到protected/components/Magus.php ,然后可以从视图中调用它

$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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM