/** * Load a file that defines model class and return that instance * * @param string $className The name of the model class to get instance * @param string $subdir * @return Model * @throws ClassUndefinedException */ public static function getModelInstance($className, $subdir = '') { $instance = false; $res = self::loadModel($className, $subdir); if ($res == false) { if (Model::isAllowVirtual()) { $tableName = NameManager::toTable($className); $instance = new Model($tableName); } } else { if (!self::classExists($className)) { self::load('ClassUndefinedException', 'exception'); throw new ClassUndefinedException($className); } $instance = new $className(); } return $instance; }
/** * Execute a SELECT statement using WHERE condition * created by the field names and values specified in the parameter * and return rows information as sql result. * * @param string $name Field names that combined by "And" * @param array $args Values for fields * @return array */ private function _selectByMethodName($name, $args) { $columns = explode('_and_', $name); $i = 0; $sel = $this->select(); foreach ($columns as $column) { $columnName = NameManager::toTable($column); $sel->where($columnName, $args[$i]); $i++; } if (count($args) > count($columns)) { $sel->order($args[$i]); } $rows = $sel->fetchAll(); return $rows; }