Il giorno lunedì 19 marzo 2012 12:23:17 UTC+1, euromark ha scritto:
For starters--App::import() is the right way to include vendor filesApp::uses() should mainly be used with cake and app stuffThe main difference:import() usually works like include/require and will load this file right awayuses() will only store the information where to find that file and the lazy loading will fetch this file only if neededI always try to avoid App::import() and vendor loading directly inside the application.Wrapping those third party classes in a Lib layer has several advantages.a) you can easily work with App::uses() internally in the appb) you can override some methods/settings if they don't make sensec) changes in how those foreign classes are used/called on updates doesn't have to effect your appd) makes use of the lazyloading from abovee) it is much easier to testexample: simle_html_domin /Lib/Utility/HtmlDomLib.php:class HtmlDomLib {public function __construct() {$res = App::import('Vendor', 'SimpleHtmlDom', array('file'=>'simple_html_dom/simple_html_dom.php')); if ($res === false) {trigger_error('simplehtmldom lib not found');}}/*** @param url or path to file content* @return object Dom* 2010-11-06 ms*/public static function domFromFile($url) {return file_get_html($url);}}anywhere in your application:App::uses('HtmlDomLib', 'Utility');$DomObject = HtmlDomLib::domFromFile($url);happy codingmark
Am Sonntag, 18. März 2012 18:58:01 UTC+1 schrieb dariob:App:import / App:uses ??
Il giorno domenica 18 marzo 2012 10:36:55 UTC+1, dariob ha scritto:What is for you the best way to implement any external php class to be avaible trough controllers or models?
We truly need to package any php class in a plugin?? And how? (cake 2.1)
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment