ThinkPHP控制器間如何相互調(diào)用方法?
Jun 07, 2016 pm 05:23 PMThinkPHP同一個(gè)項(xiàng)目里,兩個(gè)控制器的方法如何相互調(diào)用呢,ThinkPHP提供了一個(gè)A(),通過(guò)它可以使控制器之間的方法相互調(diào)用,使得代碼可以重復(fù)利用。
官方似乎對(duì)A()方法沒(méi)有相關(guān)使用文檔,現(xiàn)在通過(guò)一個(gè)例子來(lái)說(shuō)一下如使用A()方法。
? ?有兩個(gè)控制器,ColumnsAction和NewsAction。ncatlist()是ColumnsAction的分類列表方法,現(xiàn)在我要在控制器NewsAction中調(diào)用ncatlist()方法。
看代碼:
class ColumnsAction extends Action{ public function ncatlist(){ $Columns=new Model; $News = M("News"); $list=$Columns->query("SELECT concat(colPath,'-',colId) AS bpath, colId,colPid,colPath, colTitle, description,ord FROM ".C('DB_PREFIX')."columns where typeid=1 ORDER BY bpath, colId"); $this->assign('alist',$list); } } class NewsAction extends CommonAction { // 首頁(yè) public function index() { $Columns=A("Columns"); $Columns->ncatlist(); }
? ?這樣在模板中你就可以循環(huán)alist來(lái)獲取分類列表了。
? ?說(shuō)明:上面的代碼是WBlog3.0(使用thinkphp3.0的核心包)的代碼版斷,不過(guò)我查看了thinkphp3.1和thinkph3.12核心包還保留著A方法。
? ?? ??
? ?

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.
