Home Backend Development PHP Tutorial In-depth study of Tasks and views in Joomla

In-depth study of Tasks and views in Joomla

Aug 08, 2016 am 09:23 AM
joomla task view

[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);
    }
Copy after login

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.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Windows 11 shutdown prompts task host window task host is executing the shutdown task solution Windows 11 shutdown prompts task host window task host is executing the shutdown task solution Feb 12, 2024 pm 12:40 PM

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 development: How to generate views using Laravel View? Laravel development: How to generate views using Laravel View? Jun 14, 2023 pm 03:28 PM

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 learning Web application development based on Joomla Golang learning Web application development based on Joomla Jun 24, 2023 pm 12:15 PM

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: One-click installation of WordPress, Joomla and other CMS Pagoda Panel: One-click installation of WordPress, Joomla and other CMS Jun 21, 2023 pm 04:18 PM

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

Detailed explanation of C#Task Detailed explanation of C#Task Mar 14, 2024 am 09:54 AM

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.

Get a deeper understanding of tasks in C# Get a deeper understanding of tasks in C# Feb 18, 2024 pm 12:03 PM

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#.

Some of the most popular website building programs, how many do you know? Some of the most popular website building programs, how many do you know? Feb 13, 2024 pm 11:30 PM

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.

Using C# tasks Using C# tasks Feb 19, 2024 pm 12:16 PM

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

See all articles