Mapping existent Class

26 views
Skip to first unread message

Adauto Oliveira

unread,
Aug 5, 2015, 6:23:10 AM8/5/15
to redbeanphp
I would like to know how to map existent classes.

class Person{
 
public name;
 
function setName($name){
  $this
->name=$name;
 
}
 
function add($person){
     R
::store($person)
 
}

}

$fulano
= newPerson();
$fulano
->setName('Peter');
$fulano
->add($fulano);

my doubt is where and how to adapt the R::dispense() to my created class.

gabor

unread,
Aug 6, 2015, 4:53:59 AM8/6/15
to redbeanphp


That's not how RedBeanPHP works:

http://www.redbeanphp.com/models

Example:

class Person extends SimpleModel {
   
public function update() {
       
....do validation...
   
}
}



With RedBeanPHP, you never need methods like setName or add.


To set a property, just set it on the bean: $person->name = 'Jack';

To add a person as a relation: $person->ownPerson[] = $person2;

cheers
gabor
Reply all
Reply to author
Forward
0 new messages