Differences between render, redirect, and dispatch in CakePHP

Source: Internet
Author: User
Differences between render, redirect, and dispatch in CakePHP. csdn. in CakePHP, netkunshan_shenbinarticledetails6221219 redirects to three commonly used functions: render, redirect, dispatch1, and render functions publicfunctionrender (render, redirect, and dispatch in CakePHP ).
Http://blog.csdn.net/kunshan_shenbin/article/details/6221219
In CakePHP, the three functions that are frequently used for jump are render, redirect, and dispatch.
1. render function
Public function render ($ action = null, $ layout = null, $ file = null)
Render
String $ action
String $ layout
String $ file
Render rendering view, you may not often use this method, because the render method is automatically called at the end of the controller action, and outputs the view by action name command. At the same time, you can call this method at any location in the controller logic to output the view. if you want to jump to other pages in the current Controller when calling the logic in the Controller, you can use this method, for example:
After the delete function is successfully deleted, the index on the list page is displayed. Write like this
Public function delete (){
$ This-> index ();
$ This-> render (null, null, 'index ');
}
2. redirect function
Redirect
String $ url
User redirection: This method tells your users where to continue accessing. The entered URL parameter can be a Cake internal URL or a complete URL (http ://...). This method sends the browse url and then sends a new request.
3. dispatch functions
The dispatch function is in the Dispatcher class, which has
$ Dispatcher-> dispatch ($ url );
Here, the scheduler will parse the url to get the relevant parameters (among which more actions will be called, including route, to parse the url) and forward them to the corresponding controller, finally, the control is transferred to the method in the relevant controller. This method redirects to other controllers and uses render to redirect to the same Controller.
Note: call exit when the dispatch jump ends;
App::import('Core', array('Dispatcher'));......$dispatcher = new Dispatcher();$dispatcher->dispatch($this->request,$this->response,array("controller"=>"admins","action"=>"site"));        exit();

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.