src/Charcoal/Source/DatabaseSource.php
public function loadItemFromKey($key, $ident, StorableInterface $item = null)
    {
        if ($item !== null) {
            $this->setModel($item);
        } else {
            $class = get_class($this->model());
            $item  = new $class;
        }

        $key = preg_replace('/[^\w-]+/', '', $key);
        // Missing parameters
        if (!$key || !$ident) {
            return $item;
        }

        $table = $this->table();
        $query = sprintf('
            SELECT
                *
            FROM
               `%s`
            WHERE
               `%s` = :ident
            LIMIT
               1', $table, $key);

        $binds = [
            'ident' => $ident
        ];

        return $this->loadItemFromQuery($query, $binds, $item);
    }
public function loadItemFromKey($key, $ident, StorableInterface $item = null)
    {
        if ($item !== null) {
            $this->setModel($item);
        } else {
            $class = get_class($this->model());
            $item  = new $class;
        }

        $key = preg_replace('/[^\w-]+/', '', $key);
        // Missing parameters
        if (!$key || !$ident) {
            return $item;
        }

        $table = $this->table();
        $query = sprintf('
            SELECT
                *
            FROM
               `%s`
            WHERE
               `%s` = :ident
            LIMIT
               1', $table, $key);

        $binds = [
            'ident' => $ident
        ];

        return $this->loadItemFromQuery($query, $binds, $item);
    }
public function loadItemFromKey ( $ key , $ ident , StorableInterface $ item = null ) { if ( $ item !== null ) { $ this -> setModel ( $ item ) ; } else { $ class = get_class ( $ this -> model ( ) ) ; $ item = new $ class ; } $ key = preg_replace ( '/[^\w-]+/' , '' , $ key ) ; // Missing parameters if ( ! $ key || ! $ ident ) { return $ item ; } $ table = $ this -> table ( ) ; $ query = sprintf ( '
            SELECT
                *
            FROM
               `%s`
            WHERE
               `%s` = :ident
            LIMIT
               1' , $ table , $ key ) ; $ binds = [ 'ident' => $ ident ] ; return $ this -> loadItemFromQuery ( $ query , $ binds , $ item ) ; }
Load item by the given column.

@param  string                 $key   Column name.
@param  mixed                  $ident Value of said column.
@param  StorableInterface|null $item  Optional. Item (storable object) to load into.
@throws \Exception If the query fails.
@return StorableInterface
Load item by the given column .