<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Freelancer &#187; Uncategorized</title>
	<atom:link href="http://php-freelancer.in/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://php-freelancer.in</link>
	<description></description>
	<lastBuildDate>Mon, 30 Jan 2012 13:31:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CakePHP : Set More Than One Variable By One $this-&gt;set Method In Controller</title>
		<link>http://php-freelancer.in/2010/05/08/cakephp-set-more-than-one-variable-by-one-this-set-method-in-controller/</link>
		<comments>http://php-freelancer.in/2010/05/08/cakephp-set-more-than-one-variable-by-one-this-set-method-in-controller/#comments</comments>
		<pubDate>Sat, 08 May 2010 15:55:58 +0000</pubDate>
		<dc:creator>Ankur</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Set more than one variable by $this->set method]]></category>

		<guid isPermaLink="false">http://php-freelancer.in/?p=103</guid>
		<description><![CDATA[Hello Friends, Currently I am working on one CakePHP project and learning so many new things of cakePHP and today while working on one section I learn one new thing in which we can set more than one variable in controller by using only one $this-&#62;set method. I wanted to set so many variables in &#8230; <a href="http://php-freelancer.in/2010/05/08/cakephp-set-more-than-one-variable-by-one-this-set-method-in-controller/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hello Friends, Currently I am working on one CakePHP project and learning so many new things of cakePHP and today while working on one section I learn one new thing in which we can set more than one variable in controller by using only one $this-&gt;set method. I wanted to set so many variables in my controller to use it so I have searched that how we can set more than one variable in controller by $this-&gt;set method and i found that we can do that by using <a href="http://www.php.net/compact" target="_blank">compact()</a> php method. compact() takes the array you pass into it and looks for variables of the same name as the elements in that array. It then spits out an array of key =&gt; value pairs<span id="more-103"></span>.</p>
<p>So generally we use four set method to pass four variables like this<br />
<code><br />
$user = "Ankur";<br />
$foo= "Gandhi";<br />
$temp= "CakePHP";<br />
$test= "Freelancer";<br />
$this-&gt;set('user', $user);<br />
$this-&gt;set('foo', $foo);<br />
$this-&gt;set('temp', $temp);<br />
$this-&gt;set('test', $test);</code></p>
<div id="in_post_ad_middle_1" style="text-align:center;margin: 5px;padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-8444019803708971";
/* Middleofpost */
google_ad_slot = "5399229243";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>As you see in above code that we are using 4 set method to set variables to use it in view, Now please check below code to see how we can do these all things in a single set method.</p>
<p><code><br />
$user = "Ankur";<br />
$foo= "Gandhi";<br />
$temp= "CakePHP";<br />
$test= "Freelancer";<br />
$this-&gt;set(compact('user', 'foo', 'temp', 'test'));<br />
</code></p>
<p>You can see in above code that we used only one set method and compact method to set variables to use it in view.What compact will do in this? compact() takes the array you pass into it and looks for variables of the same name as the elements in that array.You must have your variables name same as you passed elements in compact. for example If your variable is $user=&#8221;Ankur&#8221;; than you have to pass user in compact to set it for view. If you will use any other variable name in compact than it will not work.</p>
<div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://php-freelancer.in/2010/05/08/cakephp-set-more-than-one-variable-by-one-this-set-method-in-controller/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: php-freelancer.in @ 2012-02-06 21:36:32 -->
