Zend2 Skeleton:无法调用/ application / index / index

时间:2015-01-09 08:32:30

标签: php zend-framework2

早上好,

我目前正在学习Zend 2,但已经拥有MVC的经验。我安装了当前的zend2框架应用程序,该应用程序可在我本地计算机上的http://learningzend.local/下访问。

现在,我正在尝试理解Zends路由,但我没有达到/ application / index / index。它返回404.

以下是module.config.php的摘录。我唯一改变的是后两种路线中的类型,最初设置为'Literal'和'Segment'而没有路径。家庭路线似乎有效:当我改变动作时,主页消失。

'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    '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'    => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/application',
                'defaults' => array(

                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Zend\Mvc\Router\Http\Segment',
                    '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(
        'Application\Controller\Index' => 'Application\Controller\IndexController'
    ),
),

控制器完全不变

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

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>

1 个答案:

答案 0 :(得分:0)

来了....解决方案!

我的VHOST conf中的Apache2设置AllowOverride在apache2.conf中执行不覆盖相同的设置,即使它们指向不同的目录。所以,去吧     $ sudo joe /etc/apache2/apache2.conf     将/ var / www的设置更改为     AllowOverride All     $ sudo service apache2 restart