示例#1
0
 public function errorAction($exception)
 {
     $this->getView()->setLayout(null);
     // 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());
     eYaf\Logger::getLogger()->logException($exception);
     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");
             break;
     }
     eYaf\Logger::stopLogging();
 }
示例#2
0
文件: Error.php 项目: tkaven/biyeyuan
 public function errorAction(E $exception)
 {
     if (Registry::get('config')->environment != 'pro') {
         echo '<pre>';
         print_r($exception);
     }
     Yaf\Dispatcher::getInstance()->autoRender(false);
     switch ($exception->getCode()) {
         case \YAF\ERR\NOTFOUND\MODULE:
         case \YAF\ERR\NOTFOUND\CONTROLLER:
         case \YAF\ERR\NOTFOUND\ACTION:
         case \YAF\ERR\NOTFOUND\VIEW:
         case 404:
             header("Content-type: text/html; charset=utf-8");
             header("status: 404 Not Found");
             $this->display("404");
             break;
         default:
             header("Content-type: text/html; charset=utf-8");
             header("status: 500 Internal Server Error");
             if (Registry::get('config')->environment == 'pro') {
                 $this->display("500");
             } else {
                 echo $exception->getMessage();
             }
             break;
     }
 }
示例#3
0
文件: Bootstrap.php 项目: airzhe/yaf
 public function _initRouter($dispatcher)
 {
     $router = Yaf\Dispatcher::getInstance()->getRouter();
     #$route = new Yaf\Route\Simple("m", "c", "a");
     #$router->addRoute("name", $route);
     $route = new Yaf\Route\Regex('/\\/product\\/([a-zA-Z]+)/', ['controller' => 'index', 'action' => 'test'], [1 => 'ident']);
     $router->addRoute('product', $route);
 }
示例#4
0
 public function _initRoute(Yaf\Dispatcher $dispatcher)
 {
     //注册路由
     $router = Yaf\Dispatcher::getInstance()->getRouter();
     $config_routes = Yaf\Registry::get("config")->routes;
     if (!empty($config_routes)) {
         $router->addConfig(Yaf\Registry::get("config")->routes);
     }
 }
示例#5
0
 public function setUp()
 {
     $this->application = Yaf\Registry::get('Application');
     if ($this->application) {
         return;
     }
     $this->application = new Yaf\Application(APPLICATION_PATH . "/config/application.ini", APPLICATION_ENVIRONMENT);
     $this->application->bootstrap();
     Yaf\Registry::set('Application', $this->application);
     Yaf\Dispatcher::getInstance()->setView(PHPUnit_MockYafView::getInstance());
 }
示例#6
0
 /**
  * Get the current page from the request query string.
  *
  * @param  int  $total
  * @param  int  $per_page
  * @return int
  */
 public static function page($total, $per_page)
 {
     $query = Yaf\Dispatcher::getInstance()->getRequest()->getQuery();
     $page = isset($query['page']) ? (int) $query['page'] : 1;
     // The page will be validated and adjusted if it is less than one or greater
     // than the last page. For example, if the current page is not an integer or
     // less than one, one will be returned. If the current page is greater than
     // the last page, the last page will be returned.
     if (is_numeric($page) and $page > ($last = ceil($total / $per_page))) {
         return $last > 0 ? $last : 1;
     }
     return static::valid($page) ? $page : 1;
 }
示例#7
0
 public function updateAction($id)
 {
     $resource = $this->getResource($id);
     if (null === $resource) {
         return $this->forwardTo404();
     }
     $model = $this->get_model_name();
     if ($resource->updateAttributes($this->get_resource_params($model))) {
         $this->redirect($this->get_index_url());
         return false;
     } else {
         Yaf\Dispatcher::getInstance()->disableView();
         echo $this->render('edit', array('resource' => $resource, 'index_url' => $this->get_index_url()));
         return false;
     }
 }
示例#8
0
 public function getView()
 {
     return Yaf\Dispatcher::getInstance()->initView(APPLICATION_VIEWS);
 }
示例#9
0
文件: _init.php 项目: Yansor/yafblog
<?php

$dis = Yaf\Dispatcher::getInstance();
//Initialize Routes for Admin module
$routes = new Yaf\Config\Ini(__DIR__ . "/config" . "/routes.ini");
$dis->getRouter()->addConfig($routes->admin);
示例#10
0
 public function _initConfig()
 {
     Yaf\Dispatcher::getInstance()->autoRender(FALSE);
     // 关闭自动加载模板
 }
示例#11
0
文件: cli.php 项目: loncool/yaf-admin
<?php

/**
 * cli方式执行请求
 * eg:
 * php cli.php "request_uri=/index/index/testcli/p1/helloworld/p2/god" 
 */
define('APPLICATION_PATH', dirname(dirname(__FILE__)));
require APPLICATION_PATH . '/vendor/autoload.php';
$application = new Yaf\Application(APPLICATION_PATH . "/conf/application.ini");
$request = new Yaf\Request\Simple();
Yaf\Dispatcher::getInstance()->dispatch($request);
示例#12
0
 public function _initRoute(Yaf\Dispatcher $dispatcher)
 {
     $router = Yaf\Dispatcher::getInstance()->getRouter();
     $route = new Yaf\Route\Rewrite('d/:domain', array('controller' => 'merchant', 'action' => 'domainHome'));
     $router->addRoute('merchant', $route);
 }