【问题标题】:Zend custom Route not working if Index controller is not capitalized?如果索引控制器未大写,Zend 自定义路由不起作用?
【发布时间】:2011-10-19 13:50:13
【问题描述】:

我正在我的共享主机上测试一个 Zend 项目。我将所有内容都保存在一个文件夹“Zend-project”中,而不是在服务器公共根目录上(因为我还有另一个项目!)。

这是结构:

/public_root
  /zend-project
    /application
      /configs
        application.ini
      /controllers
      /layouts
      /views
      bootstrap.php
    /css
    /images
    /javascript
    /zend-library
    .htaccess
    index.php

我不得不稍微调整一下项目,因为我无法在共享主机上更改我的 document_root,所以我编辑了 .htaccess 到这个:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/favicon.ico$ [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /zend-project/index.php [NC,L]

但最后似乎一切正常,除了我在引导程序中添加到路由器的单个 Url Route。

编辑:我尝试使用单个操作(称为“测试”)创建一个新控制器“TestController”。我尝试使用小写的控制器输入 url(mysite.com/zend-project/test/测试)并且它正在工作!因为我怀疑“索引”这个词本身有问题!因为任何其他控制器都可以作为一种魅力

这是 bootstrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

protected function _initRoutes()
{

    $frontController=Zend_Controller_Front::getInstance();
    $router=$frontController->getRouter();  
    $router->removeDefaultRoutes();
    $router->setGlobalParam('lang','en');
    $router->addRoute(
            'lang',
            new Zend_Controller_Router_Route(':lang/:controller/:action',
            array('lang'=>':lang',
            'module'=>'default',
            'controller'=>'index',
            'action'=>'index'

            )

            )
    );


            //the following route is not working remotely.
            //Is working on local environment
    $router->addRoute(
    'langController',
    new Zend_Controller_Router_Route(':controller/:action',
    array(

            'module'=>'default',
            'controller'=>'index',
            'action'=>'index'
            )

    )
);

            $router->addRoute(
    'langIndex',
    new Zend_Controller_Router_Route(':lang',
    array('lang'=>':lang',
            'module'=>'default',
            'controller'=>'index',
            'action'=>'index'
            )

    )
 );

            $router->addRoute(
    'langNothing',
    new Zend_Controller_Router_Route('',
    array(
            'module'=>'default',
            'controller'=>'index',
            'action'=>'index'
            )

    )
);

}
}

我尝试输入以下网址(基于我创建的自定义路由)并且一切似乎都有效:

//this points to the pair controller/action -> index/index
mysite.com/zend-project/

//this points to the pair controller/action ->index/index in english lang
mysite.com/zend-project/en

//this points to the pair controller/action ->index/rooms in english lang
mysite.com/zend-project/en/index/rooms

但每当我输入:

mysite.com/zend-project/index/index 

我收到以下消息: 未找到。在此服务器上未找到请求的 URL /zend-project/index/index。

看起来请求没有到达 index.php 文件..可能是 .htaccess 问题?或什么

谢谢

已编辑

发现通过用大写字母输入损坏的路由的控制器它可以工作:

//this works.Controller has capital letter
mysite.com/zend-project/Index/index 

//this do not work.Controller has not capital letter
mysite.com/zend-project/index/index

为什么? (顺便说一句,我在 linux 服务器上..)

【问题讨论】:

  • 这是一个奇怪的问题。我想知道mysite.com/zend-project/Index/index 如何作为关于模块的第一个索引工作,但您没有索引模块。?你能把类名也放在你的控制器上吗?
  • 我指定了一个路由 'langController' 来处理您输入 :controller/:action 时的情况。在这种情况下,控制器必须使用大写字母。我的索引控制器文件是IndexController.php,类名是IndexController
  • 老兄试试mysite.com/zend-project/langNothing这样的网址
  • 我试过了。它显示了索引操作。为什么??
  • 您不打算访问此操作吗?

标签: zend-framework shared-hosting zend-route


【解决方案1】:

从 httpd.conf 中删除它

Options Includes ExecCGI MultiViews FollowSymLinks Indexes

【讨论】:

    猜你喜欢
    • 2020-06-25
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 2017-02-01
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    相关资源
    最近更新 更多