Posts Tagged ‘discovery’
What is compact() in controller?
I don’t know how much functions in php I do not know but everyday I am finding new ones specially when I started tinkering CakePHP 1.2 last week. And my latest discovery is …. compact function. After using the console script, I found this code in the controllers$users = $this->User->Teacher->find('list'); $this->set(compact('users'));
compact is a native PHP function that creates an array containing variables and their values. Chris Hartjes explains it well in his blog. It’s quite neat because it will save me a few lines and spaces.
There you go, our new gem today: compact()


![[Bloglines]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/bloglines.png)
![[del.icio.us]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/delicious.png)
![[Facebook]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/myspace.png)
![[Newsvine]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/newsvine.png)
![[Squidoo]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/squidoo.png)
![[StumbleUpon]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/technorati.png)
![[Twitter]](http://cakephp.prometsupport.com/wp-content/plugins/bookmarkify/twitter.png)