當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Think::instance方法代碼示例

本文整理匯總了PHP中think\Think::instance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Think::instance方法的具體用法?PHP Think::instance怎麽用?PHP Think::instance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在think\Think的用法示例。


在下文中一共展示了Think::instance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: omnipotent

/**
 * 萬能字段字段類型表單處理
 * @param type $field 字段名 
 * @param type $value 字段內容
 * @param type $fieldinfo 字段配置
 * @return type
 */
function omnipotent($field, $value, $fieldinfo)
{
    $view = \Think\Think::instance('\\Think\\View');
    $setting = unserialize($fieldinfo['setting']);
    //特殊處理
    if (in_array($setting['fieldtype'], array('text', 'mediumtext', 'longtext'))) {
        $_value = unserialize($value);
        if ($value && $_value) {
            $value = $_value;
            $this->data[$field] = $value;
        }
    }
    $formtext = str_replace('{FIELD_VALUE}', $value, $setting["formtext"]);
    $formtext = str_replace('{MODELID}', $this->modelid, $formtext);
    $formtext = str_replace('{ID}', $this->id ? $this->id : 0, $formtext);
    // 頁麵緩存
    ob_start();
    ob_implicit_flush(0);
    $view->assign($this->data);
    $view->display('', '', '', $formtext, '');
    // 獲取並清空緩存
    $formtext = ob_get_clean();
    //錯誤提示
    $errortips = $fieldinfo['errortips'];
    if ($fieldinfo['minlength']) {
        //驗證規則
        $this->formValidateRules['info[' . $field . ']'] = array("required" => true);
        //驗證不通過提示
        $this->formValidateMessages['info[' . $field . ']'] = array("required" => $errortips ? $errortips : $fieldinfo['name'] . "不能為空!");
    }
    return $formtext;
}
開發者ID:sandom123,項目名稱:king400,代碼行數:39,代碼來源:form.inc.php

示例2: __construct

 public function __construct()
 {
     $this->view = \Think\Think::instance('Think\\View');
     $this->plugin_path = './plugins/' . $this->getName() . '/';
     //多語言
     if (C('LANG_SWITCH_ON', null, false)) {
         $lang_file = $this->plugin_path . "Lang/" . LANG_SET . ".php";
         if (is_file($lang_file)) {
             $lang = (include $lang_file);
             L($lang);
         }
     }
     $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
     $plugin_root = __ROOT__ . '/plugins/' . $this->getName();
     $TMPL_PARSE_STRING['__PLUGINROOT__'] = $plugin_root;
     if (is_file($this->plugin_path . 'config.php')) {
         $this->config_file = $this->plugin_path . 'config.php';
     }
     $config = $this->getConfig();
     $theme = $config['theme'];
     $depr = "/";
     $theme = empty($theme) ? "" : $theme . $depr;
     $v_layer = C("DEFAULT_V_LAYER");
     $this->tmpl_root = "plugins/" . $this->getName() . "/{$v_layer}/" . $theme;
     $TMPL_PARSE_STRING['__PLUGINTMPL__'] = __ROOT__ . "/" . $this->tmpl_root;
     C('TMPL_PARSE_STRING', $TMPL_PARSE_STRING);
 }
開發者ID:feng8605765,項目名稱:xmmusic,代碼行數:27,代碼來源:Plugin.class.php

示例3: run

 public function run(&$_data)
 {
     $engine = strtolower(C('TMPL_ENGINE_TYPE'));
     $_content = empty($_data['content']) ? $_data['file'] : $_data['content'];
     $_data['prefix'] = !empty($_data['prefix']) ? $_data['prefix'] : C('TMPL_CACHE_PREFIX');
     if ('think' == $engine) {
         // 采用Think模板引擎
         if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
             // 緩存有效
             //載入模版緩存文件
             Storage::load(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var'], 'tpl');
         } else {
             $tpl = Think::instance('Think\\Template');
             // 編譯並加載模板文件
             $tpl->fetch($_content, $_data['var'], $_data['prefix']);
         }
     } else {
         // 調用第三方模板引擎解析和輸出
         if (strpos($engine, '\\')) {
             $class = $engine;
         } else {
             $class = 'Think\\Template\\Driver\\' . ucwords($engine);
         }
         if (class_exists($class)) {
             $tpl = new $class();
             $tpl->fetch($_content, $_data['var']);
         } else {
             // 類沒有定義
             E(L('_NOT_SUPPORT_') . ': ' . $class);
         }
     }
 }
開發者ID:Backflag,項目名稱:weiphp2.0.1202,代碼行數:32,代碼來源:ParseTemplateBehavior.class.php

示例4: __construct

 public function __construct()
 {
     $this->view = \Think\Think::instance('Think\\View');
     $this->addon_path = ONETHINK_ADDON_PATH . $this->getName() . '/';
     if (is_file($this->addon_path . 'config.php')) {
         $this->config_file = $this->addon_path . 'config.php';
     }
 }
開發者ID:jayfjso,項目名稱:pinsen,代碼行數:8,代碼來源:Addon.class.php

示例5: __construct

 public function __construct()
 {
     $this->view = \Think\Think::instance('Think\\View');
     // $this->addon_path   =   ONETHINK_ADDON_PATH.$this->getName().'/';
     // $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
     // $TMPL_PARSE_STRING['__ADDONROOT__'] = __ROOT__ . '/Addons/'.$this->getName();
     // C('TMPL_PARSE_STRING', $TMPL_PARSE_STRING);
 }
開發者ID:Luckyseal,項目名稱:amango,代碼行數:8,代碼來源:AddonsController.class.php

示例6: __construct

 /**
  * 架構函數 取得模板對象實例
  * @access public
  */
 public function __construct()
 {
     Hook::listen('action_begin', $this->config);
     //實例化視圖類
     $this->view = Think::instance('Think\\View');
     //控製器初始化
     if (method_exists($this, '_initialize')) {
         $this->_initialize();
     }
 }
開發者ID:Chocol,項目名稱:think-phpunit,代碼行數:14,代碼來源:Controller.php

示例7: insert_content

 public function insert_content($dynamic = false)
 {
     $Template = Think::instance('Think\\Template');
     $templateFile = $this->load_template_file();
     if ($dynamic) {
         $this->export_theme_link($this->name, $this->theme);
     }
     // 視圖解析標簽
     $Template->fetch($templateFile, $this->view->get(), C('TMPL_CACHE_PREFIX'));
 }
開發者ID:HarrryStudio,項目名稱:microweb,代碼行數:10,代碼來源:Widget.class.php

示例8: __construct

 /**
  * 構造函數
  */
 public function __construct()
 {
     $this->view = \Think\Think::instance('Think\\View');
     $this->addon_path = ADDON_PATH . $this->getName . '/';
     $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
     $TMPL_PARSE_STRING['__ADDONROOT__'] = __APP__ . '/Addons/' . $this->getName();
     C('TMPL_PARSE_STRING', $TMPL_PARSE_STRING);
     if (is_file($this->addon_path . 'config.php')) {
         $this->config_file = $this->addon_path . 'config.php';
     }
 }
開發者ID:925800521,項目名稱:itskycms,代碼行數:14,代碼來源:Addon.class.php

示例9: _initialize

 protected function _initialize()
 {
     $this->view = \Think\Think::instance('Think\\View');
     $this->addon_path = ADDONS_PATH . $this->getName() . '/View/';
     $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
     $TMPL_PARSE_STRING['__ADDONROOT__'] = ADDONS_PATH . $this->getName();
     C('TMPL_PARSE_STRING', $TMPL_PARSE_STRING);
     if (is_file($this->addon_path . 'config.php')) {
         $this->config_file = $this->addon_path . 'config.php';
     }
 }
開發者ID:735579768,項目名稱:Ainiku,代碼行數:11,代碼來源:Plugin.class.php

示例10: __get

 public function __get($name)
 {
     if (isset(self::$_components[$name])) {
         $components = self::$_components[$name];
         if (!empty($components['class'])) {
             $class = $components['class'];
             if ($components['path'] && !class_exists($class, false)) {
                 import($components['path'], PROJECT_PATH);
             }
             unset($components['class'], $components['path']);
             $this->{$name} = \Think\Think::instance($class);
             return $this->{$name};
         }
     }
 }
開發者ID:sandom123,項目名稱:king400,代碼行數:15,代碼來源:Components.class.php

示例11: run

 public function run(&$templateFile)
 {
     if (C('CTPL_SWITCH_ON') == TRUE) {
         $view = \Think\Think::instance('Think\\View');
         $File = $view->parseTemplate($templateFile);
         if (!empty($File) && !is_file($File)) {
             $ctpl_data_path = str_replace('__COMMON_PATH__', COMMON_PATH, C('CTPL_DATA_PATH'));
             $dir = pathinfo($File);
             if (!is_dir($dir['dirname'])) {
                 mkdir($dir['dirname'], 0755, TRUE);
             }
             $content = !empty($ctpl_data_path) && is_file($ctpl_data_path) ? file_get_contents($ctpl_data_path) : '';
             file_put_contents($File, $content);
         }
     }
 }
開發者ID:baiy,項目名稱:login,代碼行數:16,代碼來源:AutoCreateTemplateBehavior.class.php

示例12: fetch

 /**
  * 渲染模板輸出
  * @param string $templateFile 模板文件名
  * @param array  $parameters   模板變量
  */
 public function fetch($templateFile, $parameters)
 {
     $view = Think::instance('Think\\View');
     $error_tpl = $view->parseTemplate(C('TMPL_ACTION_ERROR'));
     $success_tpl = $view->parseTemplate(C('TMPL_ACTION_SUCcESS'));
     if ($error_tpl === $templateFile || $success_tpl === $templateFile) {
         if (pathinfo($templateFile, PATHINFO_EXTENSION) !== 'twig') {
             $tpl = Think::instance('Think\\Template');
             echo $tpl->fetch($templateFile, $parameters);
             return;
         }
     }
     $templateFile = substr($templateFile, strlen(THEME_PATH));
     $twig = self::getInstance();
     echo $twig->render($templateFile, $parameters);
 }
開發者ID:motsqueen,項目名稱:think-twig,代碼行數:21,代碼來源:Twig.class.php

示例13: renderFile

 /**
  * 渲染模板輸出 供render方法內部調用
  * @access public
  * @param string $templateFile  模板文件
  * @return string
  */
 protected function renderFile($templateFile = '')
 {
     if (!file_exists_case($templateFile)) {
         // 自動定位模板文件
         $className = explode('\\', get_called_class());
         //行為名
         $behaviorName = str_replace('Behavior', '', end($className));
         //獲取模板文件名稱
         $filename = empty($templateFile) ? $behaviorName : $templateFile;
         $moduleName = $className[0];
         $templateFile = APP_PATH . $moduleName . '/Behavior/' . $behaviorName . '/' . $filename . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             E(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
         }
     }
     $tpl = \Think\Think::instance('Think\\View');
     $tpl->assign($this->tVar);
     return $tpl->fetch($templateFile);
 }
開發者ID:gzwyufei,項目名稱:hp,代碼行數:25,代碼來源:Behavior.class.php

示例14: __construct

 public function __construct()
 {
     $this->view = \Think\Think::instance('Think\\View');
     $this->plugin_path = './plugins/' . $this->getName() . '/';
     $TMPL_PARSE_STRING = C('TMPL_PARSE_STRING');
     $plugin_root = __ROOT__ . '/plugins/' . $this->getName();
     $TMPL_PARSE_STRING['__PLUGINROOT__'] = $plugin_root;
     if (is_file($this->plugin_path . 'config.php')) {
         $this->config_file = $this->plugin_path . 'config.php';
     }
     $config = $this->getConfig();
     $theme = $config['theme'];
     $depr = "/";
     $theme = empty($theme) ? "" : $theme . $depr;
     $v_layer = C("DEFAULT_V_LAYER");
     $this->tmpl_root = "plugins/" . $this->getName() . "/{$v_layer}/" . $theme;
     $TMPL_PARSE_STRING['__PLUGINTMPL__'] = __ROOT__ . "/" . $this->tmpl_root;
     C('TMPL_PARSE_STRING', $TMPL_PARSE_STRING);
 }
開發者ID:xiaoxianlink,項目名稱:weixin,代碼行數:19,代碼來源:Plugin.class.php

示例15: checkHTMLCache

 /**
  * 檢查靜態HTML文件是否有效
  * 如果無效需要重新更新
  * @access public
  * @param string $cacheFile  靜態文件名
  * @param integer $cacheTime  緩存有效期
  * @return boolean
  */
 public static function checkHTMLCache($cacheFile = '', $cacheTime = '')
 {
     if (!is_file($cacheFile) && 'sae' != APP_MODE) {
         return false;
     } elseif (filemtime(\Think\Think::instance('Think\\View')->parseTemplate()) > self::fileMTime($cacheFile)) {
         // 模板文件如果更新靜態文件需要更新
         return false;
     } elseif (!is_numeric($cacheTime) && is_callable($cacheTime)) {
         return $cacheTime($cacheFile);
     } elseif ($cacheTime != 0 && NOW_TIME > self::fileMTime($cacheFile) + $cacheTime) {
         // 文件是否在有效期
         return false;
     }
     //靜態文件有效
     return true;
 }
開發者ID:admpub,項目名稱:OpenCenter,代碼行數:24,代碼來源:ReadHtmlCacheBehavior.class.php


注:本文中的think\Think::instance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。