ZF framework Controllers custom Action_PHP tutorial

Source: Internet
Author: User
ZF framework Controllers custom Action. The front-end controller is the painstaking effort in the construction of MVC, because it has to instantiate objects, trigger events, establish default behaviors, and so on. its main purpose is to process all requests entering the application. Front-end control front-end controller is the painstaking effort in the formation of MVC, because it has to instantiate objects, trigger events, establish default behavior, and so on, its main purpose is to process all requests into the application. The design pattern of the Front-end Controller is applied to different MVC frameworks. the Front-end Controller we specify in Zend Framework actually refers to the Zend_Controller_Front class, this class implements the front-end controller mode. it must be noted that the front-end controller is designed as Singleton, which means that it implements the Singleton design mode, that is, we can only have one instantiated Front-end Controller. that is, we cannot directly instantiate the Front Controller, but get one.

Next we will implement a simple controller redirection and distribution.

IndexController. php is created in the controllers folder, and the index. phtml file is created in the view folder. enter http: // localhost/NowaMagicFrame1.0/in the address bar to browse.

 Registry = Zend_Registry: getInstance (); $ this-> view = $ this-> registry ['View']; $ this-> view-> baseUrl = $ this-> _ request-> getBaseUrl ();} public function indexAction () {// assign a value to the variable in index. the phtml template shows $ this-> view-> bodyTitle = 'nowamagic Frame 1.0 '; echo $ this-> view-> render ('index. phtml'); // Display template}/*** news **/public function newsAction () {// assign a value to the variable, which is displayed in news. the phtml template shows $ this-> view-> bodyTitle = 'nowamagic Fram E news '; echo $ this-> view-> render ('news. phpml'); // Display template}?>

Now I want to access the news page, you can access it through IndexContriller, because it contains the newsAction () method to implement forwarding. The specific access method is http: // localhost/NowaMagicFrame1.0/index/news/

However, this URL does not look as expected. the ideal URL should look like this: http: // localhost/NowaMagicFrame1.0/news/

How can this problem be achieved? We need to create a NewsController. php

 Registry = Zend_Registry: getInstance (); $ this-> view = $ this-> registry ['View']; $ this-> view-> baseUrl = $ this-> _ request-> getBaseUrl ();}/*** Tag homepage **/function indexAction () {echo $ this-> view-> render ('news. phtml') ;}}?>

Add an indexAction to the file.

Bytes. Front-end control...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.