table() public method

Examples: $q->table('user'); $q->table('user','u'); $q->table('user')->table('salary') $q->table(array('user','salary')); $q->table(array('user','salary'),'user'); $q->table(array('u'=>'user','s'=>'salary')); If you specify multiple tables, you still need to make sure to add proper "where" conditions. All the above examples return $q (for chaining) You can also call table without arguments, which will return current table: echo $q->table(); If multiple tables are used, "false" is returned. Return is not quoted. Please avoid using table() without arguments as more tables may be dynamically added later.
public table ( string $table = UNDEFINED, string $alias = UNDEFINED )
$table string Specify table to use
$alias string Specify alias for the table
示例#1
0
 function table($table = undefined, $alias = undefined)
 {
     if ($this->prefix && $alias == undefined) {
         $alias = $table;
     }
     return parent::table($this->prefix . $table, $alias);
 }
示例#2
0
文件: Lister.php 项目: atk4/atk4
 /**
  * Similar to setModel, however you specify array of data here. setSource is
  * actually implemented around :php:class:`Controller_Data_Array`. actually
  * you can pass anything iterateable to setSource() as long as elements of
  * iterating produce either a string or array.
  *
  * @param mixed $source
  * @param array|string|null $fields
  *
  * @return $this
  */
 public function setSource($source, $fields = null)
 {
     // Set DSQL
     if ($source instanceof DB_dsql) {
         $this->dq = $source;
         return $this;
     }
     // SimpleXML and other objects
     if (is_object($source)) {
         if ($source instanceof Model) {
             throw $this->exception('Use setModel() for Models');
         } elseif ($source instanceof Controller) {
             throw $this->exception('Use setController() for Controllers');
         } elseif ($source instanceof Iterator || $source instanceof Closure) {
             $this->iter = $source;
             return $this;
         }
         // Cast non-iterable objects into array
         $source = (array) $source;
     }
     // Set Array as a data source
     if (is_array($source)) {
         $m = $this->setModel('Model', $fields);
         $m->setSource('Array', $source);
         return $this;
     }
     // Set manually
     $this->dq = $this->app->db->dsql();
     $this->dq->table($source)->field($fields ?: '*');
     return $this;
 }
示例#3
0
文件: prefixed.php 项目: atk4/atk4
 public function table($table = UNDEFINED, $alias = UNDEFINED)
 {
     if ($this->prefix && $alias == UNDEFINED) {
         $alias = $table;
     }
     return parent::table($this->prefix . $table, $alias);
 }
示例#4
0
文件: Model.php 项目: atk4/atk4
 /** Initializes base query for this model.
  * @link http://agiletoolkit.org/doc/modeltable/dsql */
 public function initQuery()
 {
     if (!$this->table) {
         throw $this->exception('$table property must be defined');
     }
     $this->dsql = $this->db->dsql();
     $this->dsql->debug($this->debug);
     $this->dsql->table($this->table, $this->table_alias);
     $this->dsql->default_field = $this->dsql->expr('*,' . $this->dsql->bt($this->table_alias ?: $this->table) . '.' . $this->dsql->bt($this->id_field));
     $this->dsql->id_field = $this->id_field;
     return $this;
 }