Clear render_php Tutorials in the PHP Zend framework

Source: Internet
Author: User
An interest in PHP MVC occurs when ASP. Zend Framework (hereinafter referred to as ZF) can compare and understand MVC to a more core function render is confusing a record of clear process

Usually when we use ZF to implement the MVC of PHP, the most critical place is of course the controller class of the various action methods, in the action method, we determine and output content. You can find this line of the dispatch method in class abstract class Zend_controller_action $this $action ();

So how to determine and output content, is to render, but this render is a few, the following list of these situations

1 2class 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
One//$this->_helper->viewrenderer ("sidebar");
12
//$this->view->render ("sidebar.phtml");
+//$this->view ("sidebar");
15
16}
17}
18?>

Summed up, seems to be the three in the render (Welcome to add)

1. Self-render

See 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 to render the view corresponding to the other action (see the view of the action corresponding to render and not the action!)
The second sentence is the corresponding view of the action, what's the point of this (because you don't see it in many cases), this one.
The third sentence is the render-specific view file, where you might think that the first two methods actually call the Renderscript, not really. The
is explained below. The reason for the second sentence by the way. The
Zend_controller_action class's Render method is actually 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
$this->getresponse ()->appendbody (
$view->render ($script),
$name
13);
14}
You can see that a scenario is using the (proxy) Render method of the View Helper class (Viewrenderer)
The other is that when you disable the assistant, you have to do it yourself, which is why render () appears, and you disable the View Assistant to output this action the corresponding view content can be done using render ().

2. Through the View assistant Viewrenderer

It says the view helper, so let's look at the second fragment in action, with the help of a view helper
$this->_helper->viewrenderer ("sidebar");
In fact, this sentence is not the render content, but instead specifies which view to render, referring 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}
So how does the output output?
Can be in $this->_helper->viewrenderer ("sidebar"); Immediately after calling $this->render ();
But in fact you don't have to call at all, just write that sentence.
When you do not write render, the view assistant will do it for you. There is a sentence in the dispatch method in the Zend_controller_action class
$this->_helper->notifypostdispatch ();
What is _helper? is a Zend_controller_action_helperbroker class, which has this method

1 public Function Notifypostdispatch ()
2 {
3 foreach (Self::getstack () as $helper) {
4 $helper->postdispatch ();
5}
6}

You can see the Postdispatch () that called each of the assistants;
And Viewrenderer is one of the assistants, the 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 helper has helped you render, and if you render it yourself, the Smart View helper will know that you can see the $this->getrequest () in _shouldrender ()->isdispatched (), and this sentence of the dispatch method in the Zend_controller_front class: $this->_request->setdispatched (TRUE);

    • Total 2 Pages:
    • Previous page
    • 1
    • 2
    • Next page

http://www.bkjia.com/PHPjc/364271.html www.bkjia.com true http://www.bkjia.com/PHPjc/364271.html techarticle An interest in PHP MVC occurs when ASP. Zend Framework (hereinafter referred to as ZF) can compare the understanding of MVC to a more core function render is confusing a record of clear process 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.