Zend框架1.12的简单路线 [英] Simple route with Zend framework 1.12

查看:85
本文介绍了Zend框架1.12的简单路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找简单的内容,但经过多次搜索后我不知道该怎么做。我看过Zend 1.12 Route的文档,但我不太了解。

I'm looking for something that is simple but I don't know how to do it after many search. I look at the documentation of Zend 1.12 Route but I don't really understand.

我在Zend Framework中有以下页面:application / views / scripts / index /
index.phtml
contact.phtml

I have these page in the Zend Framework : application/views/scripts/index/ index.phtml contact.phtml

在应用程序/视图/布局/脚本/layout.phtml

In the application/views/layouts/scripts/layout.phtml

我想href例如contac.phtml。我正在寻找要做的事情:

I want to href to contac.phtml for example. I'm looking for something to do like :

$this->url('contact')

然后,它重定向到页面联系人...但是我试图在bootstrap.php中添加一条路线,但我没有真的不知道如何...

Then, it redirect to the page contact... But I tried to add an route in the bootstrap.php but I don't really know how...

$router->addRoute('contact',
              new Zend_Controller_Router_Route('application/scripts/index/contact.phtml'));

谢谢,

David

推荐答案

我认为这是zend框架中路由的简单代码:

I think this is the simple codes for routing in zend framework:

    在index.php上的
  • 上,您请勿触摸任何东西。在项目HomeDirectory / application / Bootstrap.php上创建项目时,将其保留为Zend默认值

  • on index.php you should not touch anything. Leave it as it is from Zend default when you create a project

包括以下内容:

protected function _initRoutes()
{
    $router = Zend_Controller_Front::getInstance()->getRouter();
    include APPLICATION_PATH . "/configs/routes.php";
}


  • 在projectHomeDirectory / application / configs /下创建一个route.php文件并在其中添加所有所需的路由,例如:

  • create a routes.php file under projectHomeDirectory/application/configs/ and add there all the routes you want, for example:

    $route = new Zend_Controller_Router_Route(
        'author',
        array(
            'controller' => 'user',
            'action'     => 'index'
        ) 
    );
    
    $router->addRoute('author', $route);
    


  • 当然,您需要创建UserController用户对示例模块和视图进行建模。

    Of course you then need to create the UserController the User model the sample module and the views.

    有用的链接:

    • http://framework.zend.com/manual/1.12/en/zend.controller.router.html

    这篇关于Zend框架1.12的简单路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆