Exemplo n.º 1
0
 public function _initLayout(Yaf_Dispatcher $dispatcher)
 {
     // Enable template layout only on admin
     // TODO: make this more accurate
     if (strpos($dispatcher->getRequest()->getRequestUri(), "admin") !== FALSE && strpos($dispatcher->getRequest()->getRequestUri(), "edit") === FALSE && strpos($dispatcher->getRequest()->getRequestUri(), "confirm") === FALSE && strpos($dispatcher->getRequest()->getRequestUri(), "logDetails") === FALSE) {
         $path = Billrun_Factory::config()->getConfigValue('application.directory');
         $view = new Yaf_View_Simple($path . '/views/layout');
         $dispatcher->setView($view);
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * @param \Yaf_Dispatcher $dispatcher
  * @param  string $jqueryVer 使用的jquery文件,默认值:jquery-1.11.2.min.js
  * @return view
  */
 public static function initYafBySooh($dispatcher, $jqueryVer = 'jquery-1.11.2.min.js')
 {
     $router = $dispatcher->getRouter();
     $router->addRoute("byVar", new \Yaf_Route_Supervar(SOOH_ROUTE_VAR));
     \Yaf_Loader::getInstance()->registerLocalNameSpace($GLOBALS['CONF']['localLibs']);
     $req = $dispatcher->getRequest();
     $tmp = $req->get('__ONLY__');
     if ($tmp == 'body') {
         \SoohYaf\Viewext::$bodyonly = true;
     }
     $tmp = trim($req->get('__VIEW__'));
     //html(default),wap,  json
     define('VIW_INC_PATH', APP_PATH . '/application/views/_inc/');
     \SoohYaf\Viewext::$jqueryVer = $jqueryVer;
     if (!empty($tmp)) {
         $tmp = strtolower($tmp);
         \Sooh\Base\Ini::getInstance()->viewRenderType($tmp);
         if ($tmp == 'jsonp') {
             \Sooh\Base\Ini::getInstance()->initGobal(array('nameJsonP' => $req->get('jsonp', 'jsonp')));
         }
     }
     //		$tmp = $dispatcher->getRequest()->get('__GZIP__');
     //		if(!empty($tmp)){
     //			$tmp = strtolower ($tmp);
     //			if($tmp=='gzip')define("ZIP_OUTPUT",$tmp);
     //		}
     $view = new \SoohYaf\Viewext(null);
     $dispatcher->setView($view);
     $dispatcher->registerPlugin(new SoohPlugin());
     return $view;
 }
Exemplo n.º 3
0
 public function _initView(Yaf_Dispatcher $dispatcher)
 {
     $uri = $dispatcher->getRequest()->getRequestUri();
     if ($uri) {
         $uriArray = explode('/', $dispatcher->getRequest()->getRequestUri());
         switch ($uriArray[1]) {
             case 'admin':
                 $viewPath = APPLICATION_PATH . '/modules/Admin/views';
                 break;
             default:
                 $viewPath = APPLICATION_PATH . '/views';
         }
         $view = new TwigAdapter($viewPath, Yaf_Registry::get('config')->get('twig')->toArray());
         $dispatcher->setView($view);
     }
 }
Exemplo n.º 4
0
 public function _init(Yaf_Dispatcher $dispatcher)
 {
     // auto start session
     Yaf_Session::getInstance()->start();
     // auto load config data
     $this->config = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('Config', $this->config);
     //auto load redis
     $redis = new Redis();
     $redis->connect($this->config->redis->host, $this->config->redis->port, $this->config->redis->timeout, $this->config->redis->reserved, $this->config->redis->interval);
     Yaf_Registry::set('Redis', $redis);
     //auto load mysql
     Yaf_Registry::set('DbRead', new Db('mysql:host=' . $this->config->mysql->read->host . ';dbname=' . $this->config->mysql->read->dbname . ';charset=' . $this->config->mysql->read->charset . ';port=' . $this->config->mysql->read->port . '', $this->config->mysql->read->username, $this->config->mysql->read->password));
     Yaf_Registry::set('DbWrite', new Db('mysql:host=' . $this->config->mysql->write->host . ';dbname=' . $this->config->mysql->write->dbname . ';charset=' . $this->config->mysql->write->charset . ';port=' . $this->config->mysql->write->port . '', $this->config->mysql->write->username, $this->config->mysql->write->password));
     // auto load model
     Yaf_Registry::set('I18n', new I18nModel($redis, $this->config->application->name, 'cn'));
     Yaf_Registry::set('Cache', new CacheModel($redis, $this->config->application->name));
     // auto load plugin
     $dispatcher->registerPlugin(new GlobalPlugin());
     // auto save request
     $request = $dispatcher->getRequest();
     // auto set ajax is no render
     if ($request->isXmlHttpRequest()) {
         $dispatcher->autoRender(false);
     }
     // auto set http protocol to action except http get protocol
     if (!$request->isGet()) {
         $dispatcher->setDefaultAction($request->getMethod());
     }
 }
Exemplo n.º 5
0
 public function _initConfig(Yaf_Dispatcher $dispatcher)
 {
     $this->config = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('config', $this->config);
     //判断请求方式,命令行请求应跳过一些HTTP请求使用的初始化操作,如模板引擎初始化
     define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod()));
     Yaf_Loader::import(APPLICATION_PATH . '/conf/defines.inc.php');
 }
Exemplo n.º 6
0
 public function _initRequest(Yaf_Dispatcher $dispatcher)
 {
     #if (!empty($this->_option) && !empty($this->_option['c']) && !empty($this->_option['a']))
     #    $dispatcher->getRequest()->setRequestUri($this->_option['c']."/".$this->_option['a']);
     $dispatcher->getRequest()->setRequestUri(basename(APPLICATION_INDEX, ".php") . "/main");
 }