In-depth study of Tasks and views in Joomla
[This article is reproduced from: Mengxi Notes]
Joomla is an excellent CMS system that allows you to quickly complete the construction of a website. It provides components, modules, and templates to meet most of your website needs. Components play an important role in this.
1. Basic knowledge
Component (component) is used to display the main data of the page. Joomla's components are designed using the MVC architecture. When a page request is generated, its URL may include task, view, layout and other information. I am here to discuss this task and view. Generally, if the URL contains task, it will not contain view. This is because Joomla believes that task completes a specific task, such as database operation, validity verification, etc., and view is responsible for display. data. The usual design is that after completing the task processing in the task, the setRedirect method will be called to guide it to a view to display the data. In fact, in Joomla, if the task is not specified in the URL, the default task is display.
2. Question
In the project, the Open graphic protocol data needs to be included in the meta data of the page. Open graphic protocol is used to provide social networks with descriptions of data to be shared. If your page is completed through a task, and then you use setRedirect in the task to jump to different views based on the data for authorization verification, and then display the data page after the verification is passed, you may encounter this problem: You need to share For this page, you added Open graphic protocol data to the meta data of this page. When you want to share it to social networking sites such as facebook, google+, etc., you will find that the data and pictures displayed on the shared page are not the data you want to display on the page. .
3. Solution
The above problem is because the Open graphic protocol data acquisition does not support jumps. If you encounter a jump, you will usually go to the homepage of the website to pick up the data, which is not what we want. The problem is setRedirect. The principle of setRedirect is that the HTML header sent to the browser contains jump instructions. The way to solve the above problem is not to use setRedirect, but to use display. Each JControllerLegacy has a display method. You only need to set the view, layout, and other data you want to pass in the input, and then call the display method. Can.
The following is the sample code:
/** * 内部跳转,用于代替setRedirect. 为什么要这样子做呢? * 因为 setRedirect他会发送一个http头到浏览器,让浏览 * 进行跳转,这样一来就多了一个网络请问, 这是其一。最 * 为主要的是setRedirect在某些不支持浏览器redirect的情况 * 下达不到效果,例如:open graphic protocal * * @param type $view 要显示的view * @param type $layout 要显示的layout, 默认为NULL */ protected function internalRedirect($view, $layout=null){ $this->input->set("view", $view); $this->input->set("layout", $layout); return $this->display(); } public function checkAvailable(){ //其他的业务代码 $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 and layout in $input (this input refers to the input parameter of the url), and then directly calling the display method of JControllerLegecy.
In the checkAvailable method, before calling internalRedirect, other parameters required by the view are also set.
A friend of Mengxi said that he encountered such a problem when building one of his websites. We discussed and analyzed the Joomla implementation code and found that the solution is actually quite easy, as long as you are familiar with Joomla component development. If you have any questions, you can talk to me
I hope this article can solve the problems you encounter.
The above introduces the in-depth study of Task and view in Joomla, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Recently, many Win11 users have reported that when shutting down, they are prompted that the taskhostwindow task host is executing the shutdown task. So what is going on? Users can enter the Desktop folder under the local registry editor, and then select AutoEndTasks in the right window to set it. Let this site carefully introduce to users the solution to this problem when shutting down. Windows 11 shutdown prompts that the taskhostwindow task host is executing the shutdown task. Solution 1. Use the key combination win key + r key, enter "regedit" and press Enter, as shown in the figure below. 2. Search for [HKEY

Laravel is one of the most popular PHP frameworks currently, and its powerful view generation capabilities are impressive. A view is a page or visual element displayed to the user in a web application, which contains code such as HTML, CSS, and JavaScript. LaravelView allows developers to use a structured template language to build web pages and generate corresponding views through controllers and routing. In this article, we will explore how to generate views using LaravelView. 1. What

Golang is a programming language with high concurrency and high reliability, which has attracted much attention in web development in recent years. Joomla is an open source content management system with good modularity and ease of use. This article uses Golang as the main development language and Joomla as the basic framework to introduce a Joomla-based Web application development method. 1. Introduction to Joomla Joomla is an open source CMS system developed based on PHP. It has many advantages, such as ease of use, flexibility

Pagoda Panel is a web-based server management software that can help users quickly deploy websites, applications and databases on Linux servers. Among them, a key function of the Pagoda Panel is the one-click installation of various open source CMS, including WordPress, Joomla, Drupal, etc. For a website administrator who is not familiar with server management, manually deploying a CMS can be a tedious task. Including the process of downloading the software, decompressing, configuring the database, and uploading the files to the server. These steps are

Task is an object used to represent asynchronous operations in C#. It is located in the System.Threading.Tasks namespace. Task provides a high-level API for handling concurrent, asynchronous operations, making it easier to write asynchronous code in .NET applications.

Detailed explanation of C#Task, specific code examples are required Introduction: In C# multi-threaded programming, Task is a commonly used programming model for implementing asynchronous operations. Task provides a simple way to handle concurrent tasks, can perform asynchronous operations in parallel on multiple threads, and can easily handle exceptions and return values. This article will introduce the use of C#Task in detail and provide some specific code examples. 1. Creating and running Tasks. Methods of creating Task objects. There are many ways to create Task objects in C#.

We all know that if you want to develop a new program yourself to build a website, the cost is quite high, and not all individuals and small and micro businesses can afford it. Fortunately, there are many open source and free website building programs on the Internet today, which can only be used by downloading and installing them directly. This open source program not only reduces the threshold for building a website, but also directly saves a lot of website construction costs. To make it easier for beginners to get started with website building, tomorrow Yiwuku will briefly introduce some of the most popular website building programs. 1. WordPress [Download] WordPress is a free open source program. WordPress can build a powerful online information publishing platform, but it is more commonly used for personalized blogs. WordPress can be used not only as a personal blog, but also as a corporate website, portal website, and business website.

C#Task usage requires an overview of specific code examples: Task is a very commonly used type in C#. It represents an executable operation that can be executed asynchronously and return results. Tasks play an important role in handling asynchronous operations, parallel processing, and improving application performance. This article will introduce the basic usage of Task and provide some specific code examples. Create and use a Task In C#, you can use the Task class to create and use an asynchronous task. Here is a way to create and use Ta
