php - Cakephp calling a function between Model and View -


let have function:

function getcarname() {    return array(1 => 'bmw', 2 => 'mercedez benz', 3 => 'renault'); } 

i use function on both model , view, should create 2 same function on apphelper , car model? correct way achieve this?

having 2 functions doing same thing bad idea violates don't repeat yourself principle.

instead, add function car model , pass data controller(s) view(s) like:

$this->set('carnames', $this->car->getcarnames()); 

the car names available in view via $carnames variable.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -