繁体   English   中英

Zend 2框架简单的网站路由

[英]Zend 2 framework simple website routing

我正在出于教育目的尝试在zend中进行简单路由。 在我发表任何言论之前,我下载了3个zend教程,4个pdf,但我仍然停留在最简单的任务上。 我什至阅读了官方文档,但仍然不明白它是如何工作的。

我正在尝试创建一个简单的引导程序“首页关于和联系”页面,但发现路由工作方式没有任何运气。 我尝试配置module / ModuleName / module.config.php添加自定义路由,但没有运气。 我是否需要每个静态页面(例如“关于”和“联系”)单独的模块,或者每个页面都有一个模块和单独的控制器? 以及如何处理路由www.example.com/有关我的全部信息,这是行不通的

这是我的module.config.php

namespace Application;

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),

            'about' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/about',
                    'defaults' => array(
                        'controller' => 'Application\Controller\About',
                        'action'     => 'index',
                    ),
                ),
            ),

在src / Application / Controler中,我有IndexControler.php和AboutController.php,在view / application / index中有index.phtml和关于phtml。

关于控制器

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http:/o/github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application\Controller;

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

class AboutController extends AbstractActionController
{
    public function indexAction()
    {
        return new ViewModel();
    }

}

我认为您缺少发票。 在您上面的module.config.php文件中,您还应该在下面的行中添加这些内容,以便您的代码开始工作。

在module.config.php中的以下代码中添加此代码

'controllers' => array(
        'invokables' => array(
            'Applcation\Controller\Index' => 'Application\Controller\IndexController',
            'Applcation\Controller\About' => 'Application\Controller\AboutController',
            'Applcation\Controller\Contact' => 'Application\Controller\ContactController',
             ),
    ),

该链接将使您更好地了解缺少的内容。 http://framework.zend.com/manual/current/zh-CN/user-guide/routing-and-controllers.html

祝好运

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM