Granada\Orm\Wrapper::for_table PHP Method

for_table() public static method

A repeat of content in parent::for_table, so that created class is ORMWrapper, not ORM
public static for_table ( $table_name, $connection_name = parent::DEFAULT_CONNECTION )
    public static function for_table($table_name, $connection_name = parent::DEFAULT_CONNECTION)
    {
        self::_setup_db($connection_name);
        return new self($table_name, array(), $connection_name);
    }

Usage Example

Example #1
0
 /**
  * Factory method used to acquire instances of the given class.
  * The class name should be supplied as a string, and the class
  * should already have been loaded by PHP (or a suitable autoloader
  * should exist). This method actually returns a wrapped ORM object
  * which allows a database query to be built. The wrapped ORM object is
  * responsible for returning instances of the correct class when
  * its find_one or find_many methods are called.
  */
 public static function factory($class_name, $connection_name = null)
 {
     $class_name = self::$auto_prefix_models . $class_name;
     $table_name = self::_get_table_name($class_name);
     if ($connection_name == null) {
         $connection_name = self::_get_static_property($class_name, '_connection_name', Orm\Wrapper::DEFAULT_CONNECTION);
     }
     $wrapper = Orm\Wrapper::for_table($table_name, $connection_name);
     $wrapper->set_class_name($class_name);
     $wrapper->use_id_column(self::_get_id_column_name($class_name));
     $wrapper->resultSetClass = $class_name::$resultSetClass;
     return $wrapper;
 }