static function load_controller() { if (false === (include CTRLSPATH . Request::$controller . '/_controller.php')) { self::exit_with_status(500, 'Could not load controller file for ' . Request::$controller . '.'); } $modelname = strtolower(ApplicationModel::filename_to_modelname(Request::$controller)); if (Application::$models->exists($modelname)) { Application::$models->{$modelname}->load(); } }
/** * $models - comma-separated string of model names (their file name, not class name). * When including a model, do so in the first line of the model file. */ function include_model($models) { $models = explode(',', str_replace(' ', '', $models)); foreach ($models as $model) { $model_name = strtolower(ApplicationModel::filename_to_modelname($model)); if (empty(Application::$models->{$model_name})) { echo "Warning: include_model: Model {$model_name} not found"; continue; } Application::$models->{$model_name}->load(); } }
private function register_assocs() { if (!System::$assocs_temp) { return; } foreach (System::$assocs_temp as $assoc_type => $assocs) { foreach ($assocs as $assoc) { $prop_name = array_shift($assoc); if ($assoc) { $params = array_shift($assoc); } else { $params = array(); } if (!isset($params['model_name'])) { if ($assoc_type == 'has_many') { $model_name = ApplicationModel::filename_to_modelname(substr($prop_name, 0, -1)); } else { $model_name = ApplicationModel::filename_to_modelname($prop_name); } } else { $model_name = $params['model_name']; unset($params['model_name']); } $this->assocs->{$prop_name} = array2obj(array('model_name' => $model_name, 'type' => $assoc_type, 'params' => $params)); } } System::$assocs_temp = array(); }