Zend框架的路由 [英] routing of Zend framework

查看:54
本文介绍了Zend框架的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 zend 项目中创建了一个模块,该模块有自己的 mvc 文件夹,这是模块的结构,

I create a module in zend project and the module has it's own mvc folders, here's the structure of the module,

我想打开位于访问模块视图中的索引页

i want to open the index page which located in the view floder of the visit module

这里是 index.phtml 的路径

here's the path of the index.phtml

InspectionSys\application\modules\visits\views\scripts\visits\index.phtml

我尝试路由到 application.ini 中的索引页面

and I try to make routing to the index page in application.ini

resources.router.routes.user.route = /visit
resources.router.routes.user.defaults.module = visits
resources.router.routes.user.defaults.controller = visit
resources.router.routes.user.defaults.action = index

当我输入 http://localhost/zendApps/InspectionSys/visit 时,它返回 404 错误页面.

when I type http://localhost/zendApps/InspectionSys/visit it returns 404 error page.

我该怎么办?

推荐答案

您的控制器名称是 visits 而不是 visit.

尝试用这个替换你的路线

Try replacing your route with this

resources.router.routes.user.route = "/visit"
resources.router.routes.user.defaults.module = visits
resources.router.routes.user.defaults.controller = visits
resources.router.routes.user.defaults.action = index

或在 bootsrap 中定义您的路线

or define your route in bootsrap

 $routeUser = new Zend_Controller_Router_Route(
    '/visit',
    array(
        'module' => 'visits'
        'controller' => 'visits',
        'action' => 'index'
    )
);
$router -> addRoute('visit', $routeUser);

<小时>

更新 1

问题似乎是由于根没有被路由到 /public.

  1. 正确的方法:您需要设置一个虚拟主机并将根指向public目录.

  1. The proper way: You need to setup a vhost and point the root to the public directory.

另一种方式:您需要重定向 public 目录中的每个请求.此文件的 .htaccess 将是

Another Way: You need to redirect every request inside public directory. The .htaccess for this file would be

RewriteRule ^\.htaccess$ - [F]

RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]

RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]

RewriteRule ^public/.*$ /public/index.php [NC,L]

这篇关于Zend框架的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆