Task and view in Joomla in-depth learning
[This article turns from: Dream Brook Notes]
Joomla is an excellent CMS system, she can allow you to quickly complete the construction of a website, she provides components, modules, templates to meet most of your website needs. and components are important.
First, the basic knowledge
Component (component) is used to display the main data for a page. The components of Joomla are based on the MVC architecture design. When a page request is generated, its URL may include information such as task, view, layout, and so on. I'm here to discuss this task and view. The generic URL will not contain a view if it contains a task, because Joomla considers the task to complete a specific task, such as database operation, validation, etc., and view is responsible for displaying the data. The usual design is that when the task is processed, the Setredirect method is called to direct the data to a view. In Joomla, the default task is display if no task is specified in the URL.
Second, the question
In the project, you need to include the open graphic protocol data in the meta data of the page. Open graphic protocol is used to provide social networks with data descriptions to share. If your page is done through a task, and then you jump to a different view for authorization verification by using Setredirect in a task, and then verify that the data page is displayed after the pass, you may encounter this problem: you need to share this page, You add open graphic protocol data to the Meta data on this page, and when you want to share it with Facebook, Google + and other social networking sites, you'll find that the data and images displayed on the share page are not the data you want to display on the page.
Third, the solution
The above problem is because open graphic protocol data acquisition does not support jump, if you encounter a jump, will generally go to the homepage to pick up data, and this is not what we want. This problem is caused by setredirect. The Setredirect principle is that the HTML header that is sent to the browser contains the jump instruction. The solution to the above problem is not to use setredirect, but to use display. Each jcontrollerlegacy has a display method, you just set the view in input, layout, and other data you want to pass past, and then call the display method.
Here is the sample code:
/** * Internal jump, used instead of setredirect. Why do you do it like this? * Because setredirect he will send an HTTP header to the browser, let browse * to jump, so that there is one more network ask, this is the first. The most important is that setredirect in some cases that do not support browser redirect * Do not release the effect, for example: Open graphic protocal * * @param type $view To display the view * @param type $layout the layout to display, the default is null * /protected function Internalredirect ($view, $layout = NULL) { $this->input->set ("View", $view); $this->input->set ("layout", $layout); return $this->display (); } Public Function checkavailable () { //Other business code $this->input->set (' Tmpl ', ' doexam '); return $this->internalredirect ("Doexam", $layout); }
The above code is written in your controller. The function Internalredirect displays the page by setting the view, layout, of the $input (which is the input parameter of the URL), and then directly calling Jcontrollerlegecy's display method.
In the Checkavailable method, other view-required parameters are set before the Internalredirect is called.
Dream Brook A friend said he was doing one of his web site encountered such a problem, we discussed and analyzed the implementation of Joomla code, found that this solution is very easy, as long as you are familiar with Joomla component development. If you have a problem, you can talk to me.
Hopefully this article will solve the problem you are experiencing.