简体   繁体   中英

Simple route with Zend framework 1.12

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.

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

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

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

$this->url('contact')

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'));

Thank you,

David

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

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

  • on projectHomeDirectory/application/Bootstrap.php include this:

     protected function _initRoutes() { $router = Zend_Controller_Front::getInstance()->getRouter(); include APPLICATION_PATH . "/configs/routes.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); 

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

Useful link:

I use the router resource plugin, I find it convenient to add the routes to my config files (for example the application.ini).

You can find an example and more documentation on the ZF website:

http://framework.zend.com/manual/1.12/en/zend.application.available-resources.html#zend.application.available-resources.router

Good luck building your ZF application!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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