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

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

WBOY
Release: 2016-06-13 10:54:09
Original
861 people have browsed it

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

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

  可以看到,第三种方法App:import是最底效率的了.
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template