简体   繁体   English

zend layout.phtml错误

[英]zend layout.phtml error

Hi I've got an error in my Zend Framework project... 嗨,我的Zend Framework项目出现错误...

It raised: 它提出:

Invalid controller specified (myweb) 指定了无效的控制器(myweb)

Here is my apache error.log : 这是我的Apache error.log

PHP Warning: Invalid argument supplied for foreach() in /var/www/myweb/application/layouts/scripts/layout.phtml on line 107 PHP警告:第107行的/var/www/myweb/application/layouts/scripts/layout.phtml中为foreach()提供了无效参数

Here's my code in layout.phtml : 这是我在layout.phtml的代码:

<?php foreach($this->category as $categories):?>

    <li><a href="<?php echo $this->url(array('controller'=>'product', 'action'=>'index','category'=> $categories['categoriesName']), null, true);?>"><div id="sidemenu"> �<?php echo $categories['categoriesName'];?></div></a></li>

    <?php endforeach;?>

Can anybody help me? 有谁能够帮助我?

The problem seems to be that for some reason your url is presenting myweb as the controller instead of what should be your controller. 问题似乎是由于某种原因,您的网址将myweb呈现为控制器,而不是您的控制器。

My guess is the you are trying to use localhost to display your application so are presenting a url similar to http://localhost/myweb/... 我的猜测是,您正在尝试使用localhost来显示您的应用程序,因此会显示类似于http://localhost/myweb/...的url http://localhost/myweb/...

While it is possible to use the localhost to view ZF applications it often becomes inconvenient as applications become more complex. 尽管可以使用localhost查看ZF应用程序,但随着应用程序变得越来越复杂,它常常变得不便。 I would suggest you use a vhost for anything more then a very simple application. 我建议您将虚拟主机用于除非常简单的应用程序之外的其他任何功能。

I'm pretty sure that when you resolve the url problem the php warning will likely fix itself. 我非常确定,当您解决url问题时,php警告可能会自行修复。

This error come because your array $this->category is blank. 出现此错误是因为数组$this->category为空。 if this is blank array or return nothing then how foreach loop will execute? 如果这是空白数组或什么也不返回,那么将如何执行foreach循环?

so first print this array and check. 因此,首先打印此数组并检查。

It seems like the variable $this->category is not set in the Controller. 似乎在控制器中未设置变量$this->category You can do this by defining $this->view->category from your controller. 您可以通过在控制器中定义$this->view->category来实现。

Mostly when using these controller generated variables in the layout script instead of the corresponding view script, you want to use the same data in every view. 通常,在布局脚本中使用这些控制器生成的变量而不是相应的视图脚本时,您希望在每个视图中使用相同的数据。 If this is the case, check this question: Sending variables to the layout in Zend Framework 如果是这种情况,请检查以下问题:将变量发送到Zend Framework中的布局

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

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