php - Dynamically set class array parameter, redbeanphp wrapper -


i'm writing wrapper redbeanphp orm,

basically instead of using

$user = r::dispense('users'); $user->name = 'zigi marx'; r::store($user); 

i so

$user = new user(); $user->name = 'zigi marx'; $user->save(); 

the way done is, have class called user extends model , model runs redbeanphp

the full code of model can found here http://textuploader.com/bxon

my problem when try set 1 many relation, in redbean done so

$user = r::dispense('users'); $user->name = 'zigi marx';  $book = r::dispense('books'); $book->name = 'lord of rings ii'; $user->ownbooks[] = $book; 

and in code

$user = new user(); $user->name = 'zigi marx'; $book = new book(); $book->name = 'lord of rings ii'; $user->ownbooks[] = $book; 

i error

notice: indirect modification of overloaded property zigi\models\user::$ownbooks has no effect

the answer: __get function in model needed changed so

public function & __get($name){     $result =& $this->__bean->{$name};     return $result; } 

your __get method returning bean property value, , cannot modify afterward. fix it, need return reference (see php manual), adding & method definition, so:

public function & __get($name){     $result =& $this->__bean->$name;     return $result; } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -