<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Loading vendor files</title>
	<atom:link href="http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/</link>
	<description>baking cakes with CakePHP</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:12:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-200955</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Sat, 21 May 2011 06:19:48 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-200955</guid>
		<description>@steven: I don&#039;t think this is possible because such variables are only visible within the method in which the include happens, i.e. they are only visible in some method of the App class. 

To get access to your variable, you have to use include/require directly. See also the documentation about the &lt;a href=&quot;http://php.net/manual/en/function.include.php&quot; rel=&quot;nofollow&quot;&gt;include function&lt;/a&gt;. However, if possible, I would avoid using a variable defined in another file as it makes the code harder to read...

Hope this helps!</description>
		<content:encoded><![CDATA[<p>@steven: I don&#8217;t think this is possible because such variables are only visible within the method in which the include happens, i.e. they are only visible in some method of the App class. </p>
<p>To get access to your variable, you have to use include/require directly. See also the documentation about the <a href="http://php.net/manual/en/function.include.php" rel="nofollow">include function</a>. However, if possible, I would avoid using a variable defined in another file as it makes the code harder to read&#8230;</p>
<p>Hope this helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steven</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-200900</link>
		<dc:creator>steven</dc:creator>
		<pubDate>Fri, 20 May 2011 10:30:05 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-200900</guid>
		<description>Hi,

I am using App::import(&#039;Vendors&#039;, &#039;somevendorfile&#039;); to import a file in my controller, but i am unable to use variable which are used in   somevendorfile.php. can anyone help me on this?

Thanks,</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am using App::import(&#8216;Vendors&#8217;, &#8216;somevendorfile&#8217;); to import a file in my controller, but i am unable to use variable which are used in   somevendorfile.php. can anyone help me on this?</p>
<p>Thanks,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-195285</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Mon, 21 Mar 2011 15:56:13 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-195285</guid>
		<description>@Calvin: Thanks for your comment!

Yes, this approach should work and it could be handy for including multiple files to avoid having multiple imports. However, I think it is a bit of overkill to use this approach to avoid the 3rd parameter when importing a single file ;-)</description>
		<content:encoded><![CDATA[<p>@Calvin: Thanks for your comment!</p>
<p>Yes, this approach should work and it could be handy for including multiple files to avoid having multiple imports. However, I think it is a bit of overkill to use this approach to avoid the 3rd parameter when importing a single file ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Calvin</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-195268</link>
		<dc:creator>Calvin</dc:creator>
		<pubDate>Mon, 21 Mar 2011 12:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-195268</guid>
		<description>When you App::import() a vendor library, does it do anything other than include() the file in your vendors directory? If not, could you simply write a vendor file that contains an include statement (or multiple include statements if your vendor library has multiple dependencies)? This way, you can use App::import(&#039;Vendors&#039;, &#039;my_vendor&#039;) in your application instead of having to using the 3rd parameter or have multiple App::import()s.</description>
		<content:encoded><![CDATA[<p>When you App::import() a vendor library, does it do anything other than include() the file in your vendors directory? If not, could you simply write a vendor file that contains an include statement (or multiple include statements if your vendor library has multiple dependencies)? This way, you can use App::import(&#8216;Vendors&#8217;, &#8216;my_vendor&#8217;) in your application instead of having to using the 3rd parameter or have multiple App::import()s.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-153054</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Fri, 19 Mar 2010 15:37:50 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-153054</guid>
		<description>@dojo: You can call the import() method wherever you want. Often it is done right before the class definition, e.g.:
&lt;code&gt;
&lt;?php
App::import(&#039;Vendors&#039;, &#039;some vendor file);

class Xy {
}
&lt;/code&gt;
Hope that helps!</description>
		<content:encoded><![CDATA[<p>@dojo: You can call the import() method wherever you want. Often it is done right before the class definition, e.g.:<br />
<pre><code>&lt;?php
App::import('Vendors', 'some vendor file);

class Xy {
}</code></pre><br />
Hope that helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dojo</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-152950</link>
		<dc:creator>dojo</dc:creator>
		<pubDate>Thu, 18 Mar 2010 22:49:28 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-152950</guid>
		<description>and where do i add the code to import the vendor at?

App::import(‘Vendors’, ‘PHPMailer’, array(‘file’ =&gt; ‘phpmailer’.DS.’class.phpmailer.php’).</description>
		<content:encoded><![CDATA[<p>and where do i add the code to import the vendor at?</p>
<p>App::import(‘Vendors’, ‘PHPMailer’, array(‘file’ =&gt; ‘phpmailer’.DS.’class.phpmailer.php’).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-130685</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Wed, 17 Jun 2009 14:52:40 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-130685</guid>
		<description>@francis: Thanks for sharing your solution!

An idea to simplify your function is to use CakePHP&#039;s Folder::findRecursive() to get the file names (as a side effect you would also get rid of using the &quot;private&quot; method Configure::__list()).</description>
		<content:encoded><![CDATA[<p>@francis: Thanks for sharing your solution!</p>
<p>An idea to simplify your function is to use CakePHP&#8217;s Folder::findRecursive() to get the file names (as a side effect you would also get rid of using the &#8220;private&#8221; method Configure::__list()).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: francis</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-130653</link>
		<dc:creator>francis</dc:creator>
		<pubDate>Wed, 17 Jun 2009 03:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-130653</guid>
		<description>correction..

&lt;code&gt;
        //store folders in current directory
	$folders = Configure::__list($dir);
	foreach($folders as $folder)
	{
		read_my_dir(&quot;{$dir}/{$folder}&quot;);
	}
&lt;/code&gt;

&quot;read_my_dir&quot; was supposed to be &quot;importVendorFolder&quot;</description>
		<content:encoded><![CDATA[<p>correction..</p>
<pre><code>//store folders in current directory
	$folders = Configure::__list($dir);
	foreach($folders as $folder)
	{
		read_my_dir("{$dir}/{$folder}");
	}</code></pre>
<p>&#8220;read_my_dir&#8221; was supposed to be &#8220;importVendorFolder&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: francis</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-130644</link>
		<dc:creator>francis</dc:creator>
		<pubDate>Wed, 17 Jun 2009 01:14:31 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-130644</guid>
		<description>i thought so.. thanks for the suggestion.. i did it and i think it worked fine.. ill post the code here.. maybe it&#039;ll be helpful to others too.. :)

&lt;code&gt;
// Recursively adds a whole folder as a vendor.
function importVendorFolder($dir)
{
	//store &quot;.php&quot; files in current directory
	$files = Configure::__list($dir, &quot;.php&quot;);
	foreach($files as $file)
	{
		//import php file.
		app::import(&quot;Vendor&quot;, $file);
	}
	//store folders in current directory
	$folders = Configure::__list($dir);
	foreach($folders as $folder)
	{
		read_my_dir(&quot;{$dir}/{$folder}&quot;);
	}	
}
&lt;/code&gt;

in here i used the built in cake function &quot;Configure::__list&quot; to check if the file is a folder or a file.. 

and to call it:
&lt;code&gt;
//parameter is path to the vendor folder.
importVendorFolder(&quot;../vendors/lib&quot;);
&lt;/code&gt;

hope this will be useful to you guys.. :D</description>
		<content:encoded><![CDATA[<p>i thought so.. thanks for the suggestion.. i did it and i think it worked fine.. ill post the code here.. maybe it&#8217;ll be helpful to others too.. :)</p>
<pre><code>// Recursively adds a whole folder as a vendor.
function importVendorFolder($dir)
{
	//store ".php" files in current directory
	$files = Configure::__list($dir, ".php");
	foreach($files as $file)
	{
		//import php file.
		app::import("Vendor", $file);
	}
	//store folders in current directory
	$folders = Configure::__list($dir);
	foreach($folders as $folder)
	{
		read_my_dir("{$dir}/{$folder}");
	}	
}</code></pre>
<p>in here i used the built in cake function &#8220;Configure::__list&#8221; to check if the file is a folder or a file.. </p>
<p>and to call it:<br />
<pre><code>//parameter is path to the vendor folder.
importVendorFolder("../vendors/lib");</code></pre>
<p>hope this will be useful to you guys.. :D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cakebaker</title>
		<link>http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/comment-page-1/#comment-130613</link>
		<dc:creator>cakebaker</dc:creator>
		<pubDate>Tue, 16 Jun 2009 14:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://cakebaker.42dh.com/2008/03/26/loading-vendor-files/#comment-130613</guid>
		<description>@francis: Thanks for your comment!

As far as I know App::import() doesn&#039;t provide such a feature. And so you have to do it manually by looping over the file names of the respective folder and calling App::import() for each file. To make this functionality reusable, you might want to put it into its own method.

Hope that helps!</description>
		<content:encoded><![CDATA[<p>@francis: Thanks for your comment!</p>
<p>As far as I know App::import() doesn&#8217;t provide such a feature. And so you have to do it manually by looping over the file names of the respective folder and calling App::import() for each file. To make this functionality reusable, you might want to put it into its own method.</p>
<p>Hope that helps!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

