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()

Tags: , , ,