Php Zend框架的路由

Php Zend框架的路由,php,zend-framework,routing,Php,Zend Framework,Routing,我在zend项目中创建了一个模块,该模块有自己的mvc文件夹,下面是该模块的结构 我想打开位于“访问”模块的“视图浏览器”中的索引页 下面是index.phtml的路径 InspectionSys\application\modules\visits\views\scripts\visits\index.phtml 我尝试在application.ini中路由到索引页 resources.router.routes.user.route = /visit resources.router.r

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

我想打开位于“访问”模块的“视图浏览器”中的索引页

下面是index.phtml的路径

InspectionSys\application\modules\visits\views\scripts\visits\index.phtml
我尝试在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
当我输入时,它返回404错误页面


我该怎么办?

您的控制器的名字是
访问
而不是
访问

试着用这个替换你的路线

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中定义您的路由

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

更新1 问题似乎是由于根目录未路由到
/public

  • 正确的方法:您需要设置vhost并将根目录指向
    public
    目录

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

    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]
    

  • 我修改它,但同样的问题!而且它也不起作用:(现在我使用公用文件夹访问所有文件!这就是.htaccess文件的问题。你的根指向哪里?@PalAla,你按照我告诉你的做了吗?放置两个.htaccess文件,一个在公用文件夹之外,一个在里面。我回答中的一个在公用文件夹之外。你是否在application.ini中启用了模块?如果你发布了你的application.ini