早上好,
我目前正在学习 Zend 2,但已经有 MVC 的经验。我安装了当前的 zend2 骨架应用程序,可以在我的本地机器上通过 http://learningzend.local/访问该应用程序。
现在,我试图理解Zends路由,但我无法访问/application/index/index。它返回 404。
以下是 module.config.php 的摘录。我唯一更改的是后两条路由中的类型,它最初设置为"文字"和"段"而不带路径。主页路线似乎有效:当我更改操作时,主页消失了。
'routes' => array(
'home' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'ApplicationControllerIndex',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'ZendMvcRouterHttpLiteral',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'ApplicationController',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'ZendMvcRouterHttpSegment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
下面几行
'controllers' => array(
'invokables' => array(
'ApplicationControllerIndex' => 'ApplicationControllerIndexController'
),
),
控制器完全不变
namespace ApplicationController;
use ZendMvcControllerAbstractActionController;
use ZendViewModelViewModel;
class IndexController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}
}
我什么都试过了。将整个骨架应用程序重置为默认值,但它没有更改任何内容。希望一些Zend大师能告诉我出了什么问题。
为了完整起见,我的VHOST条目
<VirtualHost *>
ServerName learningzend.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/learningzend.local/public/
AccessFileName .htaccess
<Directory /var/www/learningzend.local/public/>
Options Indexes FollowSymLinks MultiViews
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
来了....解决方案!
我的 VHOST conf 中的 Apache2 设置 AllowOverride 不会覆盖 apache2.conf 中的相同设置,即使它们指向不同的目录。所以,去 $ sudo joe/etc/apache2/apache2.conf 将/var/www 处的设置更改为 允许覆盖全部 $ sudo service apache2 restart