Home Backend Development PHP Tutorial cakephp中加载第三方种的一点注意的

cakephp中加载第三方种的一点注意的

Jun 13, 2016 am 10:54 AM
find gt this user users

cakephp中加载第三方类的一点注意的
在cakephp中,加载其他不相关的类,有三种方法,例子如下:

<?phpclass TasksController extends AppController {	var $name = 'Tasks'; 	function index()	{		$this->set('tasks',$this-&gt;Task-&gt;find('all')); 		/**		* 引用外部不相关类的第一种方法 ClassRegistry::init()		* 功能:包含一个类文件,生成对象并返回对象。		$users = ClassRegistry::init("User")-&gt;find('all');		$this-&gt;set('users',$users);		*/ 		/**		* 引用外部不相关类的第二种方法 Controller::loadModel()		* 直接在控制器中调用Model类,并初始化成$this-&gt;Model名		$this-&gt;loadModel("User");		$users = $this-&gt;User-&gt;find('all');		$this-&gt;set('users',$users);		*/ 		/**		* 引用外部不相关类的第三种方法 App::import()		* 只相当于include一个类文件,初始化及调用方法都要重新来。		App::import('model','User');		$User = new User();		$this-&gt;set('users',$User-&gt;find('all'));		*/	}}?&gt;
Copy after login

  可以看到,第三种方法App:import是最底效率的了.
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 Article Tags

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)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Fix: Snipping tool not working in Windows 11

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

How to Fix Can't Connect to App Store Error on iPhone

OPPO Find X7 is a masterpiece! Capture your every moment with images OPPO Find X7 is a masterpiece! Capture your every moment with images Aug 07, 2024 pm 07:19 PM

OPPO Find X7 is a masterpiece! Capture your every moment with images

OPPO Find X8 Ultra core configuration exposed! Snapdragon 8 Gen4+ Extra Large Battery OPPO Find X8 Ultra core configuration exposed! Snapdragon 8 Gen4+ Extra Large Battery Aug 22, 2024 pm 06:54 PM

OPPO Find X8 Ultra core configuration exposed! Snapdragon 8 Gen4+ Extra Large Battery

What are the string search and replace techniques in Python? What are the string search and replace techniques in Python? Oct 20, 2023 am 11:42 AM

What are the string search and replace techniques in Python?

What folder is users? What folder is users? May 28, 2021 pm 03:33 PM

What folder is users?

How to solve the problem of docker mounting directory permissions How to solve the problem of docker mounting directory permissions Feb 29, 2024 am 10:04 AM

How to solve the problem of docker mounting directory permissions

See all articles