php - CakePHP changing virtual fields at runtime -


i have product model multi site application.

depending on domain(site) want load different data.

for example instead of having name , description fields in database have posh_name, cheap_name, posh_description, , cheap_description.

if set this:

class product extends appmodel  {     var $virtualfields = array(         'name' => 'posh_name',         'description' => 'posh_description'     ); } 

then works, whether accessed directly model or via association.

but need virtual fields different depending on domain. first creating 2 sets:

var $poshvirtualfields = array(     'name' => 'posh_name',     'description' => 'posh_description' );  var $cheapvirtualfields = array(     'name' => 'cheap_name',     'description' => 'cheap_description' ); 

so these 2 sets, how assign correct 1 based on domain? have global function called ischeap() lets me know if on lower end domain or not.

so tried this:

var $virtualfields = ischeap() ? $this->cheapvirtualfields : $this->poshvirtualfields; 

this gives me error. apparently cannot assign variables in class definition this.

so put in product model instead:

function beforefind($querydata) {     $this->virtualfields = ischeap() ? $this->cheapvirtualfields : $this->poshvirtualfields;      return $querydata; } 

this works when data accessed directly model, not work when data accessed via model association.

there has got way work right. how?

well if put in constructor instead of beforefind callback seems work:

class product extends appmodel  {     var $poshvirtualfields = array(         'name' => 'posh_name',         'description' => 'posh_description'     );      var $cheapvirtualfields = array(         'name' => 'cheap_name',         'description' => 'cheap_description'     );      function  __construct($id = false, $table = null, $ds = null) {         parent::__construct($id, $table, $ds);         $this->virtualfields = ischeap() ? $this->cheapvirtualfields : $this->poshvirtualfields;     } } 

however, not sure if cakephp no no can come bite me?


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -