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...