Autoloading RedBeanPHP Models

1,481 views
Skip to first unread message

norry

unread,
Feb 15, 2012, 10:17:47 AM2/15/12
to redbeanphp
Hello,

I wonder how can I autoload my RedBeanPHP Models?


Example:
class Model_Band extends RedBean_SimpleModel {
public function update() {
if (count($this->ownBandmember)>4) {
throw new Exception('too many!');
}
}
}


I put this into my folder Models/Model_Band.class.php.
I also registered a __autoload() function but I will not be called.

Can you help me? How can I "lazy load" the models only when I need
them?


Thanks!





Mochammad Masbuchin

unread,
Feb 15, 2012, 6:19:03 PM2/15/12
to redbe...@googlegroups.com
I'm concerned about this too. It will be great if RedBean has PSR-0 compliant autoloader ( https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md ) and support composer / packagist http://packagist.org/about-composer.

> --
> You received this message because you are subscribed to the Google Groups "redbeanphp" group.
> To post to this group, send email to redbe...@googlegroups.com.
> To unsubscribe from this group, send email to redbeanorm+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redbeanorm?hl=en.
>

Knud Potente

unread,
Nov 23, 2012, 7:28:30 PM11/23/12
to redbe...@googlegroups.com
I was able today to install RedbeanPHP via Composer. 

It seems that an *official* packagist entry for Redbean exists at gabordemooij/redbean.

I was able to install Redbean using a simple "require": {"gabordemooij/redbean": "3.*"} entry in my composer.json file.

The only 'gotcha' seems to be, that the 'R' class is not the default 'facade' - so the instructions in the Redbean manual won't work. To overcome that, at the top of my php file, right after including the composer autoloader, I added:

use RedBean_Facade as R;

That seemed to do the trick, but I don't know whether this is the 'recommended' way of using Redbean with composer. It would be wonderful if Gabor could add an entry in the manual about this, to help people like me who are 'easily confused'! ;-)

It's awesome that Redbean keeps evolving, and adapting to the latest and greatest technologies! Thank you, Gabor! :-)

gabor

unread,
Nov 24, 2012, 2:02:15 PM11/24/12
to redbe...@googlegroups.com


Hi,

You can use RedBeanPHP like that, perfectly valid.
The problem with composer is that it does not really fit into the RedBeanPHP design.
The R-class is a class compiled by Replica, the idea is that you can assemble your own custom RedBeanPHP installation.
However if you're not interested in this and you dont want to be able to call plugin functions using R, then simply aliasing RedBean_Facade with R does the trick and will not cause any suprises, so feel free to do so.

I will add a manual page for this. However my time is very limited so please have patience.

Cheers,
Gabor

gabor

unread,
Nov 24, 2012, 2:04:56 PM11/24/12
to redbe...@googlegroups.com

You can add your own Model Mapper, it's easy:

http://redbeanphp.com/manual/how_fuse_works

Cheers,
Gabor

Rodrigo Polo

unread,
Aug 5, 2015, 6:23:10 AM8/5/15
to redbeanphp
If you are using ReadBean 4.2 here is the require on the composer.json

"gabordemooij/redbean": "4.2"

and the fix:

use RedBeanPHP\Facade as R;
Reply all
Reply to author
Forward
0 new messages