Monday, 15 March 2010

php - Passing variables to a has_one relationship in PhpActiveRecord -


I am using phpactiverecord () in a project.

I have definded the following relationships, is there any way to pass a variable, so I can change language_id on the fly?

  is stable $ is_on = array (array ('language', 'class_name' = & gt; pages_lang ',' conditions' => array ('language_id = 1'))) ;   

I looked at the docs and it appears that you can do this:

  is static $ is_on = array (array ('language', ' Class_name '= & gt;' pages_lang ',' conditions' = & gt; array ('language_id =?', '1')));   

but going through a variable:

  Fixed $ has_one = array (array ('language', 'class_name' => 'Pages_lang ',' Conditions' = & gt; array ('language_id =?', $ Language_id)));   

Text "itemprop =" text ">

Static Variables are understood only in the context of objects that an object of that kind has actually been created (instantiated) before they come into existence

I am not sure That's what you are trying to achieve here, but you probably want to change the variables at some point in the control flow of your program. Make a call within a client that should make a call and set the value of that stable variable (recommended, see the code below for example) or set it explicitly with your main code (not recommended , Your variable is also required for public )

  square fu {static $ has_one = 'initial value'; public stable work sethos ($ value) { Self :: $ has_one = $ value;}} / main code: foo :: set ons ('new value');   

For simplicity I have used a string variable here, but it works only with arrays.

No comments:

Post a Comment