public function _initRest(Yaf\Dispatcher $dispatcher) { $dispatcher->disableView(); //如果不是cli就调用rest路由 if (!$dispatcher->getRequest()->isCli()) { $router = $dispatcher->getRouter(); $route = new RestRoute(); $router->addRoute("rest", $route); //设置模板目录 $view_engine = new Yaf\View\Simple(APPLICATION_PATH . '/application/views'); $dispatcher->setView($view_engine); //启用权限控制插件 $auth = new AuthPlugin(); $dispatcher->registerPlugin($auth); } else { $command = new CommandLinePlugin(); $dispatcher->registerPlugin($command); } }
public function _initView(Yaf\Dispatcher $dispatcher) { $view = new \SlatePF\Extras\ExtrasView(); $path = $view->getScriptPath(); // plain text TEST $view->on('txt', function ($file, $data) use($path) { return file_get_contents($path . $file) . ' THIS IS JUST A TEST'; }); // twig $view->on('twig', function ($file, $data) use($path) { $loader = new Twig_Loader_Filesystem($path); $twig = new Twig_Environment($loader); return $twig->loadTemplate($file)->render($data); }); //protobuf $view->on('pb', function ($file, $data) use($path) { include $path . $file; exit; }); $dispatcher->disableView(); // disable auto-render $dispatcher->setView($view); }
/** * 初始化模板引擎 */ public function _initView(Yaf\Dispatcher $dispatcher) { $dispatcher->disableView(); }