Yii自定义Widget,加载器错误
请帮助我解决这个问题(我在 Windows 本地主机上使用 Yii、Xampp):
所以...我在“protected\components\views\Magus.php”中创建了一个新的小部件。
<?php
class Magus extends CWidget {
//////////////////////////////
public function run()
{
echo '<p style="color:blue; ">Trallala :) !</p>'; // do something.
}
//////////////////////////////
} //end class
它在这里使用(“protected/views/layouts/main.php”):
<?php
$this->widget('/views/Magus');
?>
这会导致加载器(?)错误:
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
但是如果小部件文件直接放置在“protected\components”中,则不会发生该错误。该错误的原因是什么以及如何纠正?先感谢您 !
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的路径。
我建议您将您的小部件 php 文件放入
protected/components/Magus.php
中,然后您可以从视图中调用它,或者您可以将它保存在您拥有它的文件夹中并像这样调用它:
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 withOr you can keep it in folder where you have it and call it like this: