当前位置: 首页>>代码示例>>PHP>>正文


PHP plugins::construct方法代码示例

本文整理汇总了PHP中plugins::construct方法的典型用法代码示例。如果您正苦于以下问题:PHP plugins::construct方法的具体用法?PHP plugins::construct怎么用?PHP plugins::construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plugins的用法示例。


在下文中一共展示了plugins::construct方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct()
 {
     /*****************
      * GENERAL SETUP *
      *****************/
     // Guess at the baseModel name if none has been set. Use the controller's basename as the guess
     if (!$this->baseModel) {
         $this->baseModel = ucfirst(str_replace('_Controller', '', get_class()));
     }
     // Instantiate sessions
     $this->session = Session::instance();
     if (!request::is_ajax()) {
         $this->session->set('ajax.base_controller', strtolower(Router::$controller));
         $this->session->set('ajax.base_method', strtolower(Router::$method));
     }
     // Instantiate internationalization
     $this->i18n = i18n::instance();
     /**
      * TODO: This is so nasty...
      */
     if (!empty($_POST['lang'])) {
         if (empty(i18n::$langs[$_POST['lang']])) {
             die;
         }
         $this->session->set('lang', $_POST['lang']);
         echo i18n::$langs[$_POST['lang']];
         die;
     }
     // Create a static validator, if one does not already exist. By default we populate it with post variables
     // This will hold all errors that occur within Doctrine and provides easy access for the controller to grab those errors
     // Note carefully that this is intentionally a singleton - Doctrine does not otherwise know which controller is associated
     // with which record. This implies that your errors will get stacked up on top of each other, but since it's one controller
     // per run of Kohana, we should be OK here. You can also use Kohana's validation class methods here, too.
     // FIXME: This should be moved!!!
     self::$validation = new Validation($_POST);
     // Setup anything related to this website's pages rendering
     Event::run('bluebox.setup', $this);
     // Setup anything related to authenticating the user
     Event::run('bluebox.authenticate', $this);
     // Setup anything related to authorizing the user
     Event::run('bluebox.authorize', $this);
     /*******************
      * RENDERING SETUP *
      *******************/
     // For safety, fail back to HTML if this is not set
     if (!defined('CONTENT_TYPE')) {
         // take all the URL elements used for routing and explode on /
         $pathParts = explode('/', Router::$current_uri);
         $content_type = 'html';
         foreach ($pathParts as $part) {
             // see if there is an extension on each part
             $extension = pathinfo($part, PATHINFO_EXTENSION);
             // if we find a html, json, xml extension then save it, keeping the last found extension
             if (!empty($extension) && in_array(strtolower($extension), array('html', 'json', 'xml'))) {
                 $content_type = strtolower($extension);
             }
         }
         define('CONTENT_TYPE', $content_type);
     }
     // Set the default template, viewName and failback view to use, based on the content type.
     // NOTE: It's perfectly fine to override this in the template setup hooks
     switch (CONTENT_TYPE) {
         case 'json':
             $this->viewParams['template'] = 'json/layout';
             $this->viewParams['name'] = Router::$controller . '/json/' . Router::$method;
             $this->viewParams['fallback'] = 'NO CONTENT';
             break;
         case 'xml':
             $this->viewParams['template'] = 'xml/layout';
             $this->viewParams['name'] = Router::$controller . '/xml/' . Router::$method;
             $this->viewParams['fallback'] = '<xml><error>No Content</error></xml>';
             break;
         default:
             if (request::is_ajax() or !empty($_REQUEST['qtipAjaxForm'])) {
                 $this->viewParams['template'] = 'ajax';
             } else {
                 $this->viewParams['template'] = 'layout';
             }
             $this->viewParams['name'] = Router::$controller . '/' . Router::$method;
             $this->viewParams['fallback'] = 'ERROR: There is no viewable content for this page';
             break;
     }
     // NOTE: You can optionally set $viewFolder here to try an alternate folder for all views.
     // If the view doesn't exist, $viewFolder is ignored
     $this->viewParams['folder'] = '';
     // Call all setup hooks related to content type.
     Event::run('bluebox.createtemplate.' . CONTENT_TYPE, $this);
     /********************
      * PREPARE TEMPLATE *
      ********************/
     $this->template = $this->viewParams['folder'] . $this->viewParams['template'];
     // Call our parent controller's constructor
     // NOTE: This prepares our view and converts $this->template into an object.
     // Changes to $this->viewParams['template'] are ignored past this point
     parent::__construct();
     /*******************
      * PREPARE CONTENT *
      *******************/
     if (CONTENT_TYPE == 'html') {
         // Initialize default HTML content
//.........这里部分代码省略.........
开发者ID:Jaybee-,项目名称:bluebox,代码行数:101,代码来源:bluebox.php


注:本文中的plugins::construct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。