0

我已经在 localhost 上安装了 Zend Framework(版本 1.12),我在从 IndexController 访问操作时遇到问题,但是相同的代码,相同的操作名称在其他控制器中运行良好,比如说 TestController。

class IndexController extends Zend_Controller_Action {
public function init(){/* Initialize action controller here */}
public function indexAction(){//some code}
public function addAction(){//some code}
public function otherAction(){//other code}
}

class TestController extends Zend_Controller_Action {
public function init(){/* Initialize action controller here */}
public function indexAction(){//some code}
public function addAction(){//some code}
public function otherAction(){//other code}  
}

当我在地址栏输入 zf.local/ 时,我从 index/index.phtml 文件中接收内容,但是当我输入 zf.local/index/index ZF 时,告诉我找不到 url。当我输入 zf.local/test/index 时,一切正常如果我在地址栏中输入 zf.local/index/add 我收到 404 错误,但如果我输入 zf.local/test/add 一切正常。

我已将我的虚拟主机设置为 AllowOverride All,并从 Apache 启用了重写模块。我停止、重新启动并重新加载 apache,重新启动我的电脑。我认为 apache 或虚拟主机没有问题,这就是我写这篇文章的原因. 我的 apache 和虚拟主机配置

一旦我尝试输入 zf.local/default/index/add 并且代码正在运行,所以我需要在地址栏中的 /index 之前放置一个 /default

我认为这可以通过 Zend 助手在 Zend 框架的 /index 官方文档之前插入我的 url /default 来解决,但我不知道该怎么做。到目前为止,我只设法得到错误

从 index.html 我用下一个代码从控制器调用动作:

<a href="<?php echo $this->url(array('controller' => 'index',
        'action' => 'add'));
    ?>">Add</a>
4

2 回答 2

0

在视图文件中尝试以下操作以获取正确的 url

<a href="<?php echo $this->url(array('module' => 'default', 'controller' => 'index',
    'action' => 'add'));
?>">Add</a>
于 2013-04-03T09:53:10.050 回答
0

您的 ZF 应用程序创建不正确。首先尝试从命令行创建应用程序。之后这个问题就解决了。

于 2013-04-02T13:17:02.927 回答