Skip to content

Dev.Pi\Db\Table\AbstractTableGateway

linzongshu edited this page Oct 20, 2015 · 2 revisions

Brief

This class allowed user to use API to assemble sql. Codes to get its instance is:

Pi::model('<table name>', '<module name>', $options);
// Alternative
Pi::db()->model('<module name>/<table name>', $options);

Pi Gateway model introduce the possible value of $options parameter.

More examples:

$model = Pi::model('module');
$rowset = $model->find('system', 'name');
$rowset = $model->select(['name' => 'system']);

APIs

setAdapter

setAdapter(Adapter $adapter)

Set Pi\Db\Adapter\Adapter instance, which uses for creating connection driver.

Parameters

  • $adapter

Adapter instance.

select

select($where = null)

Get Pi\Db\Sql\Select instance or select result directly.

Parameters

  • $where

Where condition, can be Pi\Db\Sql\Where instance or array.

Return

Return value is Pi\Db\Sql\Select instance if $where is null, or else, Zend\Db\ResultSet\ResultSet instance contain search results set will be returned.

Examples

// Return select instance
$select = Pi::model('module')->select()->where(['name' => 'user']);
$rowset = Pi::model('module')->selectWith($select);

// Return result directly
$rowset = Pi::model('module')->select(['name' => 'user']);

// Use where closure
$model  = Pi::model('module');
$select = $model->select()->where(function ($where) {
    $where->like('name', 'system');
    return $where;
});
$rowset = $model->selectWith($select);
Clone this wiki locally