Clear the render_PHP tutorial in phpZendFramework-php Tutorial

Source: Internet
Author: User
Clarify the render in phpZendFramework. Asp. when netmvc was interested in phpmvc, I looked at ZendFramework (ZF) it can be compared and understood that mvc is very confused about the render function, which is a core function. for a while, we record the clarification process. Generally, when we are interested in php mvc in asp.net mvc, we will look at Zend Framework (ZF) it can be compared and understood that mvc is very confused about a core function render.

When we use ZF to implement php mvc, the most important thing is the various action methods of the Controller class. in the action method, we determine and output the content. in the dispatch method of class abstract class Zend_Controller_Action, you can find this line $ this-> $ action ();

So how to determine and output the content is to render, but there are several render, which are listed below

1 2 class IndexController extends Zend_Controller_Action
3 {
4 public function contactAction ()
5 {
6 // $ this-> render ("index ");
7 // $ this-> render ();
8 // $ this-> renderScript ("sidebar. phtml ");
9
10
11 // $ this-> _ helper-> viewRenderer ("sidebar ");
12
13 // $ this-> view-> render ("sidebar. phtml ");
14 // $ this-> view ("sidebar ");
15
16}
17}
18?>

To sum up, this seems to be the third render (please add)

1. Self-render

First, first
// $ This-> render ("index ");
// $ This-> render ();
// $ This-> renderScript ("sidebar. phtml ");
This is the render method that uses the Zend_Controller_Action class directly.
The first sentence is render's view corresponding to another action (see the view corresponding to the render action rather than executing the action !)
The second sentence render corresponds to the view of the action. what is the significance of this statement (because you cannot see this statement in many cases.
The third sentence is a specific render view file. here you may think that the first two methods actually call this renderScript, but this is not the case.
The following describes the reasons for the second sentence.
The render Method of the Zend_Controller_Action class actually has the following render function code with two branches:

1 public function render ($ action = null, $ name = null, $ noController = false)
2 {
3 if (! $ This-> getInvokeArg ('noviewrenderer') & $ this-> _ helper-> hasHelper ('viewrenderer ')){
4 return $ this-> _ helper-> viewRenderer-> render ($ action, $ name, $ noController );
5}
6
7 $ view = $ this-> initView ();
8 $ script = $ this-> getViewScript ($ action, $ noController );
9
10 $ this-> getResponse ()-> appendBody (
11 $ view-> render ($ script ),
12 $ name
13 );
14}
One scenario is to use the (proxy) render method of The View assistant class (viewRenderer ).
The other is that when the assistant is disabled, you have to go into the game in person. This is why render () appears, after you disable the View assistant, you can use render () to output the corresponding view content of this action.

2. View assistant viewRenderer

The View assistant is mentioned above. let's look at the second segment in the action, which is carried out by the view assistant.
// $ This-> _ helper-> viewRenderer ("sidebar ");
In fact, this sentence is not the render content, but specifies which View to render. for details, refer to the function of the Zend_Controller_Action_Helper_ViewRenderer class.

1 public function direct ($ action = null, $ name = null, $ noController = null)
2 {
3 $ this-> setRender ($ action, $ name, $ noController );
4}
How is output?
You can directly call $ this-> _ helper-> viewRenderer ("sidebar"); and then call $ this-> render.
But you don't need to call it at all. just write that sentence.
When you do not write a render, The View assistant will complete it for you. there is such a sentence in the dispatch method in the Zend_Controller_Action class.
$ This-> _ helper-> policypostdispatch ();
_ Helper? Is a Zend_Controller_Action_HelperBroker class, which has this method

1 public function policypostdispatch ()
2 {
3 foreach (self: getStack () as $ helper ){
4 $ helper-> postDispatch ();
5}
6}

The postDispatch () of each assistant is called ();
ViewRenderer is one of the assistants. its postDispatch method is as follows:

1 public function postDispatch ()
2 {
3 if ($ this-> _ shouldRender ()){
4 $ this-> render ();
5}
6}
It is here that the view assistant helps you render. if you render yourself, the Smart View assistant will know that you can view the _ shouldRender () in the $ this-> getRequest ()-> isDispatched (), and the dispatch method in the Zend_Controller_Front class: $ this-> _ request-> setDispatched (true );

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next page

Http://www.bkjia.com/PHPjc/364271.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364271.htmlTechArticleasp.net mvc on php mvc occurred interest looked at Zend Framework (hereinafter referred to as ZF) can be compared to understand mvc on a relatively core function render is very confused a while to record the process of clarity is usually in...

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.