Search code examples
phpmysqlredbean

how to create column alias in select from database by redbeanphp?


i want to know how create a query such as this in redbeanphp:

select concat(first_name,' ',last_name) AS fullname from person;

i know redbean has a bindFunc Method but i do not know how to do this and this topic was not cover in redbean Documentation .


Solution

  • I would not use the bindFunc functions, they are not meant for these kind of things. I recommend to use a FUSE model.

    Just add a class named Model_Person (extends SimpleModel) docs: http://www.redbeanphp.com/models Now add a method called getDisplayName() or something, inside this method you do something like:

    public function getDisplayName() { return $this->bean->firstName . ' ' . $this->bean->lastName; }

    Now you can do this:

    $person = R::load('person', $id); echo $person->getDisplayName();

    and it will show the full name...

    Hope this helps, cheers Gabor