RedBeanPHP Documentation

repository·master·Indexed 25 days ago

https://github.com/gabordemooij/redbean

An easy-to-use ORM for PHP featuring an 'on-the-fly' schema approach that automatically creates tables and columns as you interact with objects. Supports installation via single-file distribution or Composer.

Tokens
447
Snippets
2
Records
4
Agent score
31%

What's inside RedBeanPHP

  1. Create Models when using Composer

    master

    When using RedBeanPHP via Composer, you must adjust how you define Models due to namespacing requirements.

    1. Instead of extending RedBean_SimpleModel, you must extend \RedbeanPHP\SimpleModel.
    2. You must specify the namespace for SimpleModel.
    3. To use the R:: static methods inside your Model, you should include use \RedbeanPHP\R; at the top of your file.
  2. Install RedBeanPHP via Composer

    master

    You can install RedBeanPHP using Composer by adding it to your composer.json file.

    Note: This method is not recommended by the author. When using Composer, the core R class is namespaced as \RedbeanPHP\R. To use the standard R alias, you must include a use statement in your PHP files.

    To use the short R alias:

    use \RedbeanPHP\R as R;
    {
        "require": {
            "gabordemooij/redbean": "dev-master"
        }
    }
  3. Quick Example: Storing an object

    master

    RedBeanPHP allows you to create and persist objects (beans) with minimal code. You use R::dispense to create a new bean of a specific type and R::store to save it to the database. RedBeanPHP will automatically create the necessary tables and columns.

    $book = R::dispense("book");
    $book->author = "Santa Claus";
    $book->title = "Secrets of Christmas";
    $id = R::store( $book );