Reputation: 15778
Is there something like the Java Bean stuff in PHP? Thank you.
Upvotes: 2
Views: 5426
Reputation: 61
java bean is good for managing your resource as it implement the right MVC framework. here are a simple tutorial to implement it on PHP.
https://webdevchoices.wordpress.com/2011/08/21/applying-bean-pattern-in-php-programming/
and here is a snippet for those who are to lazy to click the link
class Person {
private $_firstName;
private $_lastName;
public function setFirstName($value) {
$v = trim($value);
$this->_firstName = empty($v) ? null : $v;
}
public funtion getFirstName() {
return $this->_firstName;
}
public function setLasttName($value) {
$v = trim($value);
$this->_lastName = empty($v) ? null : $v;
}
public funtion getLastName() {
return $this->_lastName;
}
}
Upvotes: -1
Reputation: 89
In PHP MVC frameworks such as CakePHP, ZF, Symfony etc...you could say that the equivalent of a JavaBean would be the Model itself (the M) of MVC. A model is where you would have the get / set functionalities that javabeans do. Just FYI, in Symfony, that is called an "entity"
Upvotes: 4
Reputation: 19
Have you heard about red bean php?
Try it and you will experience a great new world.
A great php ORM
Upvotes: 0
Reputation: 20102
not by default... but frameworks are something similar because the framework (usually) allows you to to map the POST or GET, build forms and save the info into the db, according to a Model... Like when using beans.. =)
Upvotes: 0