Zend2 骨架:无法调用 /application/index/index
Zend2 Skeleton: can't call /application/index/index
早上好,
我目前正在学习 Zend 2,但已经有 MVC 方面的经验。我安装了当前的 zend2 骨架应用程序,可以在我的本地机器上的 http://learningzend.local/ 下访问它。
现在,我正在尝试了解 Zends 路由,但无法访问 /application/index/index。它 returns 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>
来了....解决方案!
我的 VHOST conf 中的 Apache2 设置 AllowOverride 不会覆盖 apache2.conf 中的相同设置,即使它们指向不同的目录。所以,去
$ 须藤乔 /etc/apache2/apache2.conf
将 /var/www 处的设置更改为
允许覆盖所有
$ sudo service apache2 restart
早上好,
我目前正在学习 Zend 2,但已经有 MVC 方面的经验。我安装了当前的 zend2 骨架应用程序,可以在我的本地机器上的 http://learningzend.local/ 下访问它。
现在,我正在尝试了解 Zends 路由,但无法访问 /application/index/index。它 returns 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>
来了....解决方案!
我的 VHOST conf 中的 Apache2 设置 AllowOverride 不会覆盖 apache2.conf 中的相同设置,即使它们指向不同的目录。所以,去 $ 须藤乔 /etc/apache2/apache2.conf 将 /var/www 处的设置更改为 允许覆盖所有 $ sudo service apache2 restart