Example #1
0
 public function run()
 {
     $this->groupTable = Sys_Database::getTable('worker');
     $this->alarmModel = $this->loadModel();
     if ($this->getRequest()->getPost('o') == 'delete') {
         $gid = $this->getRequest()->getPost('gid');
         $this->delete($gid);
     }
     if ($this->getRequest()->getQuery('o') == 'edit') {
         Yaf_Dispatcher::getInstance()->disableView();
         $this->initView();
         $configData = array();
         $id = $this->getRequest()->getQuery('id');
         if ($id) {
             $configDataTmp = $this->alarmModel->selectData($id, 1, 1, $this->groupTable);
             $configData = $configDataTmp[0];
         }
         $this->display('addworker', array('D' => $configData));
     }
     if ($this->getRequest()->getQuery('o') == 'add') {
         $this->add();
     }
     $page = $this->getRequest()->getQuery('p');
     $alarmList['page'] = $page ? $page : 1;
     $id = $this->getRequest()->getQuery('pluginid');
     $pid = $id ? $id : NULL;
     $limit = 20;
     $alarmList['list'] = $this->alarmModel->selectData($pid, ($alarmList['page'] - 1) * $limit, $limit, $this->groupTable);
     $alarmNum = $this->alarmModel->selectData($pid, -1, -1, $this->groupTable);
     $alarmList['num'] = $alarmNum['num'];
     $alarmList['pageCount'] = (int) ($alarmList['num'] / $limit) + 1;
     $alarmList['pageView'] = $this->page($alarmList['page'], $alarmList['pageCount']);
     $this->getView()->assign('alarmList', $alarmList);
 }
Example #2
0
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $config = \Yaf_Registry::get('configarr');
     $dispatcher = Yaf_Dispatcher::getInstance();
     $twig = '';
     // view 放在module 目录里
     if ($request->module == $config['application']['dispatcher']['defaultModule']) {
         $twig = new \Core_Twig(APP_PATH . 'views', $config['twig']);
     } else {
         $twig = new \Core_Twig(APP_PATH . 'modules/' . $request->module . '/views', $config['twig']);
     }
     // url generate
     $twig->twig->addFunction("url", new Twig_Function_Function("Tools_help::url"));
     // 语言对应
     $twig->twig->addFunction("lang", new Twig_Function_Function("Tools_help::lang"));
     // 图片路径
     $twig->twig->addFunction("fbu", new Twig_Function_Function("Tools_help::fbu"));
     // 数字验证
     $twig->twig->addFunction("is_numeric", new Twig_Function_Function("is_numeric"));
     // 处理错误提醒
     $session_key = array('ErrorMessageStop', 'ErrorMessage', 'Message');
     foreach ($session_key as $value) {
         $twig->assign($value, Tools_help::getSession($value));
         Tools_help::setSession($value, '');
     }
     $dispatcher->setView($twig);
 }
Example #3
0
 /**
  * 路由分发开始
  *
  * @see Yaf_Plugin_Abstract::routerShutdown()
  */
 public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     //IIS不支持默认路由,采用URL Query String方式路由
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     $route = new Yaf_Route_Simple('m', 'c', 'a');
     $router->addRoute('Windows-IIS-Supervar', $route);
 }
Example #4
0
 function _initRoute()
 {
     # 路由
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     # 静态页面
     $router->addRoute('html', new Yaf_Route_Regex('/([a-z]+)\\.html$/', array('controller' => 'Index', 'action' => 'html'), array(1 => 'page')));
 }
Example #5
0
File: Rest.php Project: wuxw/YYF
 /**
  * 初始化 REST 路由
  * 修改操作 和 绑定参数
  * @method init
  * @author NewFuture
  */
 protected function init()
 {
     Yaf_Dispatcher::getInstance()->disableView();
     //关闭视图模板引擎
     $action = $this->_request->getActionName();
     //数字id映射带info控制器
     if (is_numeric($action)) {
         $this->_request->setParam('id', intval($action));
         $path = substr(strstr($_SERVER['PATH_INFO'], $action), strlen($action) + 1);
         $action = $path ? strstr($path . '/', '/', true) : 'info';
         $this->_request->setActionName($action);
     }
     //对应REST_Action
     $method = $this->_request->getMethod();
     $rest_action = $method . '_' . $action;
     /*检查该action操作是否存在,存在则修改为REST接口*/
     if (method_exists($this, $rest_action . 'Action')) {
         /*存在对应的操作*/
         $this->_request->setActionName($rest_action);
     } elseif (!method_exists($this, $action . 'Action')) {
         /*action和REST_action 都不存在*/
         $this->response = array('error' => '未定义操作', 'method' => $method, 'action' => $action, 'controller' => $this->_request->getControllerName());
         exit;
     }
     //put请求写入GOLBAL中
     $method == 'PUT' and parse_str(file_get_contents('php://input'), $GLOBALS['_PUT']);
 }
Example #6
0
 /**
  *Scaffold action识配
  */
 protected function ScaffoldRoute()
 {
     if (!$this->Scaffold) {
         return;
     }
     $this->set('controller', $this->getRequest()->getControllerName());
     $this->allParams();
     Yaf_Dispatcher::getInstance()->disableView();
     $action = $this->getRequest()->getActionName();
     if ($action == 'c') {
         $this->scaffoldC = TRUE;
         $action = $this->getRequest()->getParam('action');
     }
     switch ($action) {
         case 'scaffoldajax':
             $this->ScaffoldAjax();
             break;
         case 'scaffold':
             $this->ScaffoldIndex();
             break;
         case 'getrow':
             $this->ScaffoldGetrow();
             break;
         case 'modify':
             $this->ScaffoldModify();
             break;
         case 'remove':
             $this->ScaffoldRemove();
             break;
         default:
             $this->ScaffoldIndex();
     }
 }
Example #7
0
 public function __construct()
 {
     $app = self::app();
     if (!is_null($app)) {
         throw new Yaf_Exception('Only one application can be initialized');
     }
     Yaf_G::init();
     //这里主要是配置文件的加载
     // request initialization
     if (isset($_SERVER['REQUEST_METHOD'])) {
         //判断http请求还是cli请求
         $request = new Yaf_Request_Http();
         //获取请求的url路径和基础路径,以及请求方式
     } else {
         $request = new Yaf_Request_Cli();
     }
     if ($request == null) {
         throw new Yaf_Exception('Initialization of request failed');
     }
     // dispatcher
     $this->_dispatcher = Yaf_Dispatcher::getInstance();
     //将调度对象赋值给app对象的属性,并在调度对象的属性中添加路由对象,单例
     if ($this->_dispatcher == null || !$this->_dispatcher instanceof Yaf_Dispatcher) {
         throw new Yaf_Exception('Instantiation of dispatcher failed');
     }
     $this->_dispatcher->setRequest($request);
     //把请求对象赋值给调度对象的属性中
     self::$_app = $this;
 }
Example #8
0
 public function init()
 {
     if (Yaf_Session::getInstance()->has('username')) {
         $this->getView()->assign('username', Yaf_Session::getInstance()->offsetGet('username'));
     } else {
         return $this->redirect('/Login');
     }
     $dsn = 'mysql:host=127.0.0.1;dbname=yafdemo;charset=utf8';
     $username = '******';
     $password = '******';
     $dbo = new PDO($dsn, $username, $password);
     $dbo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
     $dbo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
     $dbo->exec('SET NAMES UTF8');
     $this->dbo = $dbo;
     $request = $this->getRequest();
     $module = strtolower($request->getModuleName());
     $controller = strtolower($request->getControllerName());
     $action = strtolower($request->getActionName());
     if (!$this->_checkPerm($module, $controller, $action) && $action != 'logout') {
         $this->getView()->setScriptPath(APPLICATION_PATH . "/application/views");
         $this->getView()->display('common/403.phtml');
         Yaf_Dispatcher::getInstance()->autoRender(FALSE);
         exit;
     }
 }
Example #9
0
 public function _initRoute()
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     // Article detail router [伪静态]
     $route = new Yaf_Route_Rewrite('/article/detail/:articleID', array('controller' => 'article', 'action' => 'detail'));
     $router->addRoute('regex', $route);
 }
Example #10
0
 /**
  * @runInSeparateProcess
  */
 public function testCase036()
 {
     $testData = array(0 => array('url' => '/', 'expected' => array('m' => null, 'c' => null, 'a' => null, 'args' => array())), 1 => array('url' => '/foo', 'expected' => array('m' => null, 'c' => 'foo', 'a' => null, 'args' => array())), 2 => array('url' => '/foo/', 'expected' => array('m' => null, 'c' => 'foo', 'a' => null, 'args' => array())), 3 => array('url' => '/foo///bar', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array())), 4 => array('url' => 'foo/bar', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array())), 5 => array('url' => '/foo/bar/', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array())), 6 => array('url' => '/foo/bar/dummy', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => null))), 7 => array('url' => '/foo///bar/dummy', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => null))), 8 => array('url' => 'foo/bar/dummy', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => null))), 9 => array('url' => '/my', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 10 => array('url' => '/my/', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 11 => array('url' => '/my/foo', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())), 12 => array('url' => '/my/foo/', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())), 13 => array('url' => '/my/foo/bar', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array())), 14 => array('url' => '/my/foo/bar/', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array())), 15 => array('url' => '/my/foo/bar/dummy/1', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => '1'))), 16 => array('url' => 'my/foo/bar/dummy/1/a/2/////', 'expected' => array('m' => 'my', 'c' => 'foo', 'a' => 'bar', 'args' => array('dummy' => '1', 'a' => '2'))), 17 => array('url' => '/my/index/index', 'expected' => array('m' => 'my', 'c' => 'index', 'a' => 'index', 'args' => array())), 18 => array('url' => '/my/index', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'index', 'args' => array())), 19 => array('url' => '/foo/index', 'expected' => array('m' => null, 'c' => 'foo', 'a' => 'index', 'args' => array())), 20 => array('url' => 'index/foo', 'expected' => array('m' => null, 'c' => 'index', 'a' => 'foo', 'args' => array())));
     $config = array("application" => array("directory" => '/tmp/', "modules" => 'Index,My'));
     $app = new Yaf_Application($config);
     $route = Yaf_Dispatcher::getInstance()->getRouter();
     foreach ($testData as $index => $test) {
         $req = new Yaf_Request_Http($test['url']);
         $route->route($req);
         $this->assertEquals($test['expected']['m'], $req->getModuleName(), 'Failed module test for url:' . $test['url']);
         $this->assertEquals($test['expected']['c'], $req->getControllerName(), 'Failed controller test for url:' . $test['url']);
         $this->assertEquals($test['expected']['a'], $req->getActionName(), 'Failed action test for url:' . $test['url']);
         $this->assertEquals($test['expected']['args'], $req->getParams(), 'Failed param test for url:' . $test['url']);
     }
     if (!defined('YAF_MODE')) {
         Yaf_G::iniSet('yaf.action_prefer', true);
     } else {
         ini_set('yaf.action_prefer', true);
     }
     $testDataActionPrefer = array(0 => array('url' => '/', 'expected' => array('m' => null, 'c' => null, 'a' => null, 'args' => array())), 1 => array('url' => '/foo', 'expected' => array('m' => null, 'c' => null, 'a' => 'foo', 'args' => array())), 2 => array('url' => '/foo/', 'expected' => array('m' => null, 'c' => null, 'a' => 'foo', 'args' => array())), 3 => array('url' => '/my', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 4 => array('url' => '/my/', 'expected' => array('m' => null, 'c' => 'my', 'a' => null, 'args' => array())), 5 => array('url' => '/my/foo', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())), 6 => array('url' => '/my//foo', 'expected' => array('m' => null, 'c' => 'my', 'a' => 'foo', 'args' => array())));
     foreach ($testDataActionPrefer as $index => $test) {
         $req = new Yaf_Request_Http($test['url']);
         $route->route($req);
         $this->assertEquals($test['expected']['m'], $req->getModuleName(), 'Failed module test for url:' . $test['url']);
         $this->assertEquals($test['expected']['c'], $req->getControllerName(), 'Failed controller test for url:' . $test['url']);
         $this->assertEquals($test['expected']['a'], $req->getActionName(), 'Failed action test for url:' . $test['url']);
         $this->assertEquals($test['expected']['args'], $req->getParams(), 'Failed param test for url:' . $test['url']);
     }
 }
Example #11
0
 function errorAction($exception)
 {
     // fallback views path to global when error occured in modules.
     $config = Yaf_Application::app()->getConfig();
     $this->getView()->setScriptPath($config->application->directory . "/views");
     $this->getView()->e = $exception;
     $this->getView()->e_class = get_class($exception);
     $this->getView()->e_string_trace = $exception->getTraceAsString();
     $params = $this->getRequest()->getParams();
     unset($params['exception']);
     $this->getView()->params = array_merge(array(), $params, $this->getRequest()->getPost(), $this->getRequest()->getQuery());
     switch ($exception->getCode()) {
         case YAF_ERR_AUTOLOAD_FAILED:
         case YAF_ERR_NOTFOUND_MODULE:
         case YAF_ERR_NOTFOUND_CONTROLLER:
         case YAF_ERR_NOTFOUND_ACTION:
             header('HTTP/1.1 404 Not Found');
             break;
         case 401:
             $this->forward('Index', 'application', 'accessDenied');
             header('HTTP/1.1 401 Unauthorized');
             Yaf_Dispatcher::getInstance()->disableView();
             echo $this->render('accessdenied');
             break;
         default:
             //header("HTTP/1.1 500 Internal Server Error");
             core::dump($exception);
             break;
     }
 }
Example #12
0
 /**
  * Controller的init方法会被自动首先调用
  */
 public function init()
 {
     //调试mysql
     if (isset($_GET['debug6429360'])) {
         $this->debug = true;
         DB_Mysqli::$DEBUG = 1;
     }
     $this->platform = isset($_REQUEST['platform']) ? $_REQUEST['platform'] : $this->platform;
     Yaf_Registry::set("platform", $this->platform);
     $this->isMobile = $this->platform == 'ios' || $this->platform == 'android';
     $this->wap = !$this->isMobile && Common_Mobile::isMobile();
     $this->uid = $this->get('uid', $this->post('uid', false));
     $this->controllerName = $this->getRequest()->getControllerName();
     $this->actionName = $this->getRequest()->getActionName();
     $userModel = new UserModel();
     /*        if (!isset(Common_Config::$NotNeedLogin[$this->controllerName][$this->actionName])
                 && $this->isMobile 
                 && $this->needLogin 
                 && !$this->debug) 
             {
                 $token = $this->get("token", $this->post("token", false));
                 if (!$token) {
                     $this->redirect(NULL, Common_Error::ERROR_TOKEN_NOT_EXISTS);
                 }
     
                 $api = $this->getRequestApi();
                 $check = Common_Token::check($token, $this->uid, strtolower($api));
                 if (!$check) {          
                     $this->redirect(NULL, Common_Error::ERROR_TOKEN);
                 }
             }*/
     $this->uid = $this->uid ? $this->uid : $userModel->getUid();
     /**
      * 如果是Ajax请求, 则关闭HTML输出
      */
     if ($this->getRequest()->isXmlHttpRequest() || 'POST' == $this->getRequest()->getMethod()) {
         $this->ajax = true;
         Yaf_Dispatcher::getInstance()->disableView();
     } else {
         //$path = $this->getView()->getScriptPath();
         //$path[0] = $path[0] . "/" . strtolower($this->getRequest()->getControllerName());
         //$this->getView()->setScriptPath($path[0]);
     }
     //print_r($this->uid?$this->uid:"null");
     //验证登录
     /*if (
                 !isset(Common_Config::$NotNeedLogin[$this->controllerName][$this->actionName]) 
                 && $this->needLogin 
                 && !$this->uid) {
                 $this->redirect("/user/login?from=" . (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""), Common_Error::ERROR_USER_NOT_LOGIN);
     
                 $this->redirect("/user/verify", Common_Error::ERROR_USER_NOT_LOGIN);
             }*/
     //用户信息
     /*        if($this->uid) {
                 $user = $userModel->getUser($this->uid);
                 $this->assign("uInfo", $user);
                 Yaf_Registry::set("uid", $this->uid);
             }*/
 }
Example #13
0
 public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $view = new TZ_View();
     $view->setCacheEnable(true);
     $view->setScriptPath(APP_PATH . '/application/modules/' . $request->getModuleName() . '/views');
     Yaf_Dispatcher::getInstance()->setView($view);
 }
Example #14
0
 /**
  * 路由规则定义,如果没有需要,可以去除该代码
  * 
  * @param Yaf_Dispatcher $dispatcher
  */
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     $config = new Yaf_Config_Ini(APPLICATION_PATH . '/conf/route.ini', 'common');
     if ($config->routes) {
         $router = Yaf_Dispatcher::getInstance()->getRouter();
         $router->addConfig($config->routes);
     }
 }
Example #15
0
 /**
  *初始化路由
  */
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     /**
      * 添加配置中的路由
      */
     $router->addConfig(Yaf_Registry::get("config")->routes);
 }
Example #16
0
 /**
  * 错误控制入口
  * 
  * @param Exception $exception
  * @return boolean
  */
 public function errorAction(Exception $exception)
 {
     //判断当前请求是否是AJAX
     $request = Yaf_Dispatcher::getInstance()->getRequest();
     $is_ajsx = $request->isXmlHttpRequest();
     $is_ajsx ? $this->_ajax($exception) : $this->_html($exception);
     return false;
 }
 public function _initConfig()
 {
     Yaf_Dispatcher::getInstance()->autoRender(FALSE);
     // 关闭自动加载模板
     //把配置保存起来
     $arrConfig = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('config', $arrConfig);
 }
Example #18
0
 /**
  * 初始化路由
  */
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     //$router->addRoute('movie', $route);
     //$route = new Yaf_Route_Map(true, "_");
     //$router->addRoute('map_defaut', $route);
     //$router->addConfig($this->__config->routes);
 }
Example #19
0
 public function init()
 {
     if ($this->getRequest()->isCli()) {
         Yaf_Dispatcher::getInstance()->returnResponse(true);
         Yaf_Dispatcher::getInstance()->disableView();
     } else {
         throw new Exception("Environment is not in CLI mode.\n");
     }
 }
Example #20
0
 public function init()
 {
     parent::init();
     //关闭自动加载template功能
     Yaf_Dispatcher::getInstance()->autoRender(false);
     if ($this->_req->isPost()) {
         $this->checkReffer(array(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ""));
     }
 }
Example #21
0
 public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $view = new View();
     $config = Yaf_Registry::get('config');
     if (!empty($config->path->view)) {
         $view->setScriptPath($config->path->view);
     }
     Yaf_Dispatcher::getInstance()->setView($view);
 }
Example #22
0
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     // $route = new Yaf_Route_Rewrite('product/:ident',array('module'=>'User','controller' => 'Index','action' => 'test'));
     //使用路由器装载路由协议
     //$router->addRoute('product', $route);
     $route = new Yaf_Route_Rewrite('cc', array('controller' => 'Index', 'action' => 'index'));
     //使用路由器装载路由协议
     $router->addRoute('cc', $route);
 }
Example #23
0
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     //在这里注册自己的路由协议,默认使用简单路由
     //print_r( $routes = Yaf_Dispatcher::getInstance()->getRouter()->getRoute("default"));
     Yaf_Dispatcher::getInstance()->getRouter()->addRoute("supervar", new Yaf_Route_Supervar("r"));
     Yaf_Dispatcher::getInstance()->getRouter()->addRoute("simple", new Yaf_Route_simple('m', 'c', 'a'));
     $route = new Yaf_Route_Rewrite("/index/get", array("controller" => "item", "action" => "get"));
     Yaf_Dispatcher::getInstance()->getRouter()->addRoute("product", $route);
     //$dispatcher->setDefaultModule("index")->setDefaultController("index")->setDefaultAction("index");
 }
Example #24
0
 private function getTpl($tpl)
 {
     $backTract = debug_backtrace();
     $isViewCalled = FALSE;
     foreach ($backTract as $v) {
         if ($v['class'] === 'Yaf_View_Simple') {
             $isViewCalled = TRUE;
             break;
         }
     }
     $config = Yaf_Application::app()->getConfig();
     $dispatcher = Yaf_Dispatcher::getInstance();
     $this->fileType = $config->application->view->ext;
     $request = $dispatcher->getRequest();
     $module = strtolower($request->module);
     $controller = strtolower($request->controller);
     $searchSlash = strpos($tpl, '//');
     if (strpos($tpl, '.' . $this->fileType) === FALSE) {
         // view里的display|render的时候,后缀名给丢了,这边给补回来
         $tpl .= '.' . $this->fileType;
     }
     if ($searchSlash !== FALSE) {
         // 出现这种情况的时候表示,调用display|render的时候用的是/作为开头的,模板的查找路径顺序为
         // /modules/{modules}/views/
         // /views/
         $tpl = substr($tpl, $searchSlash + 2);
         $pathArray = array(APP_PATH . 'modules/' . $module . '/views/', APP_PATH . 'views/');
         $path = $this->_returnExistsFile($pathArray, $tpl);
         if ($path === FALSE) {
             throw new Exception('Failed opening template', YAF_ERR_NOTFOUND_VIEW);
         }
         $this->setScriptPath($path);
         return $tpl;
     } else {
         // 调用时不是用/为开头,这边在view里调用和在controller里调用是有所不同的,view调用的时候没有了所在的controller名称,这种情况下查找路径顺序为
         // /modules/{modules}/views/{controller}/
         // /views/{controller}/
         // /views/
         if ($isViewCalled !== TRUE) {
             // 把{controller}/脱出
             $controllerPath = $controller . '/';
             $searchPath = strpos($tpl, $controllerPath);
             if ($searchPath === 0) {
                 $tpl = substr($tpl, strlen($controllerPath));
             }
         }
         $pathArray = array(APP_PATH . 'modules/' . $module . '/views/' . $controller . '/', APP_PATH . 'views/' . $controller . '/', APP_PATH . 'views/');
         $path = $this->returnExistsFile($pathArray, $tpl, $controller);
         if ($path === FALSE) {
             throw new Exception('Failed opening template', YAF_ERR_NOTFOUND_VIEW);
         }
         $this->setScriptPath($path);
         return $tpl;
     }
 }
Example #25
0
 public function indexAction()
 {
     //默认Action
     Yaf_Dispatcher::getInstance()->disableView();
     //禁用view
     $this->getView()->assign("content", "Hello World");
     echo 'asdf';
     // $cacheDriver = new \Doctrine\Common\Cache\ArrayCache();
     // $cacheDriver->setMemcache($memcache);
     // $cacheDriver->save('cache_id', 'my_data');
 }
Example #26
0
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     //$router->addConfig($this->_config->routes);
     $matches = array();
     if (preg_match('/^\\/([A-Za-z0-9_\\-\\.]+)[\\/]?([A-Za-z0-9_\\-\\.]*)[\\/]?([A-Za-z0-9_\\-\\.]*).*$/', $_SERVER['REQUEST_URI'], $matches)) {
         #DebugTools::print_r($matches);
     }
     $route = new Yaf_Route_Regex('#^/xyq/#', array('controller' => isset($matches[2]) && !empty($matches[2]) ? $matches[2] : 'index', 'action' => isset($matches[3]) && !empty($matches[3]) ? $matches[3] : 'index'));
     $router->addRoute('xyq', $route);
     //DebugTools::print_r($router);
 }
Example #27
0
 protected function renderTemplate($name)
 {
     try {
         Yaf_Dispatcher::getInstance()->disableView();
         $module = $this->_request->getModuleName();
         $this->_view->setScriptPath(APPLICATION_PATH . 'modules/' . $module . '/views/');
         return $this->_view->render('templates/' . $name . '.tpl');
     } catch (Exception $e) {
         Logger::write($e->__toString(), Zend_Log::ERR);
         return false;
     }
     return true;
 }
Example #28
0
 public function errorAction($exception = null)
 {
     Yaf_Dispatcher::getInstance()->disableView();
     $code = $exception->getCode();
     $message = $exception->getMessage();
     $url = $this->_request->getRequestUri();
     Log::write('[' . $code . '](' . $url . '):' . $message, 'ERROR');
     $response['status'] = -10;
     $response['info'] = ['code' => $code, 'msg' => '请求异常!', 'uri' => $url];
     header('Content-type: application/json');
     echo json_encode($response, JSON_UNESCAPED_UNICODE);
     //unicode不转码
 }
Example #29
0
 public function _initRoute()
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     // rewrite
     $route = new Yaf_Route_Rewrite('/article/detail/:articleID', array('controller' => 'article', 'action' => 'detail'));
     $router->addRoute('rewrite', $route);
     // rewrite_category
     $route = new Yaf_Route_Rewrite('/article/detail/:categoryID/:articleID', array('controller' => 'article', 'action' => 'detail'));
     $router->addRoute('rewrite_category', $route);
     // regex
     $route = new Yaf_Route_Regex('#article/([0-9]+).html#', array('controller' => 'article', 'action' => 'detail'), array(1 => 'articleID'));
     $router->addRoute('regex', $route);
 }
Example #30
0
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     // $routes = $this->_config->routes;
     // //不为空
     // if (!empty($routes)) {
     //   //通过派遣器得到默认的路由器
     //   $router = Yaf_Dispatcher::getInstance()->getRouter();
     //   //添加配置中的路由
     //   $router->addConfig($routes);
     $route = new Yaf_Route_Rewrite('product/:ident', array('controller' => 'Product', 'action' => 'upload'));
     Yaf_Dispatcher::getInstance()->getRouter()->addRoute("product", $route);
     // }
 }