RedBeanPHP\Repository\Fluid::load PHP Method

load() public method

It searches for a OODBBean Bean Object in the database. It does not matter how this bean has been stored. RedBean uses the primary key ID $id and the string $type to find the bean. The $type specifies what kind of bean you are looking for; this is the same type as used with the dispense() function. If RedBean finds the bean it will return the OODB Bean object; if it cannot find the bean RedBean will return a new bean of type $type and with primary key ID 0. In the latter case it acts basically the same as dispense(). Important note: If the bean cannot be found in the database a new bean of the specified type will be generated and returned.
public load ( string $type, integer $id ) : RedBeanPHP\OODBBean
$type string type of bean you want to load
$id integer ID of the bean you want to load
return RedBeanPHP\OODBBean
    public function load($type, $id)
    {
        $bean = $this->dispense($type);
        if (isset($this->stash[$this->nesting][$id])) {
            $row = $this->stash[$this->nesting][$id];
        } else {
            try {
                $rows = $this->writer->queryRecord($type, array('id' => array($id)));
            } catch (SQLException $exception) {
                if ($this->writer->sqlStateIn($exception->getSQLState(), array(QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, QueryWriter::C_SQLSTATE_NO_SUCH_TABLE))) {
                    $rows = 0;
                }
            }
            if (empty($rows)) {
                return $bean;
            }
            $row = array_pop($rows);
        }
        $bean->importRow($row);
        $this->nesting++;
        $this->oodb->signal('open', $bean);
        $this->nesting--;
        return $bean->setMeta('tainted', FALSE);
    }