/** * 获取model对象 * @param string $modelName 名称 * @return object 返回 instance of BaseModel对象 */ public function getModel($modelName = '') { if (empty($modelName)) { $modelName = preg_replace('/Service$/i', '', ClassUtil::getClassName(get_class($this))); } $modelName = 'App\\Models\\' . ucfirst($modelName); if (!class_exists($modelName)) { throw new \Exception(get_lang('CLASS_NOT_FOUND', $modelName)); } return new $modelName(); }
private static function cgiRegister() { $di = get_app_di(); $config = self::getConfig(); self::registCommonService($di, $config); $di->setShared('router', function () { $router = new \Phalcon\Mvc\Router(); $router->removeExtraSlashes(true); $router->add('/:controller/:action/:params', array('controller' => 1, 'action' => 2, 'params' => 3)); return $router; }); $di->setShared('dispatcher', function () { $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach('dispatch:beforeException', new NotFoundPlugin()); $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($eventsManager); $dispatcher->setDefaultNamespace("App\\Controllers\\"); return $dispatcher; }); $di->setShared('view', function () use($config) { $view = new \Phalcon\Mvc\View(); $view->setViewsDir($config->view->templatePath); $view->registerEngines(array('.html' => function ($view, $di) { $config = $di->get('config'); $compiledPath = $config->view->compiledPath; if (!file_exists($compiledPath)) { mkdir($compiledPath, 0744, true); } $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di); $volt->setOptions(array('compiledPath' => $compiledPath, 'compiledExtension' => $config->view->compiledExtension, 'compileAlways' => isset($config->view->compileAlways) ?: false)); $compiler = $volt->getCompiler(); $compiler->addExtension(new VoltExtension()); $autoEscape = isset($config->view->autoEscape) ?: true; ClassUtil::modifyPrivateProperties($compiler, array('_autoescape' => $autoEscape)); return $volt; })); return $view; }); $di->setShared('elements', function () { return new ElementsPlugin(); }); }