Posts Tagged ‘discovery’
What is compact() in controller?
Warning: fopen(/home/promet/public_html/cakephp/wp-content/plugins/devformatter/geshi/geshi/php.php) [function.fopen]: failed to open stream: Permission denied in /home/promet/public_html/cakephp/wp-content/plugins/devformatter/devgeshi.php on line 103
Warning: fopen(/home/promet/public_html/cakephp/wp-content/plugins/devformatter/geshi/geshi/php.php) [function.fopen]: failed to open stream: Permission denied in /home/promet/public_html/cakephp/wp-content/plugins/devformatter/devgeshi.php on line 103
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()

