本文整理汇总了PHP中Think类的典型用法代码示例。如果您正苦于以下问题:PHP Think类的具体用法?PHP Think怎么用?PHP Think使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Think类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run(&$_data)
{
$engine = strtolower(C('TMPL_ENGINE_TYPE'));
if ('think' == $engine) {
// 采用Think模板引擎
if ($this->checkCache($_data['file'])) {
// 缓存有效
// 分解变量并载入模板缓存
extract($_data['var'], EXTR_OVERWRITE);
//载入模版缓存文件
include C('CACHE_PATH') . md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX');
} else {
$tpl = Think::instance('ThinkTemplate');
// 编译并加载模板文件
$tpl->fetch($_data['file'], $_data['var']);
}
} else {
// 调用第三方模板引擎解析和输出
$class = 'Template' . ucwords($engine);
if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
// 内置驱动
$path = CORE_PATH;
} else {
// 扩展驱动
$path = EXTEND_PATH;
}
if (require_cache($path . 'Driver/Template/' . $class . '.class.php')) {
$tpl = new $class();
$tpl->fetch($_data['file'], $_data['var']);
} else {
// 类没有定义
throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
}
}
}
示例2: __construct
/**
* 架构函数 取得模板对象实例
* @access public
*/
public function __construct()
{
Hook::listen('action_begin', $this->config);
//实例化视图类
$this->view = Think::instance('Think\\View');
/****************************************/
//站点的配置信息
$this->siteConfig = array('sitedomain' => 'http://localhost/ecshoptk');
$this->assign('config', $this->siteConfig);
$this->assign('tplstyle', ROOT_PATH . '/Public/');
$this->assign('ecs_css_path', 'http://localhost/ecshoptk/public/css/style.css');
$this->assign('ecs_images_path', 'http://localhost/ecshoptk/public/images/');
$this->assign('ecs_data_path', 'http://localhost/ecshoptk/public/data/');
$_CFG = ecs_load_config();
foreach ($_CFG as $k1 => $v1) {
C($k1, $v1);
}
/****************************************/
/****************************************/
//语言配置信息
include ROOT_PATH . 'Public/languages/zh_cn/common.php';
$this->assign('lang', $_LANG);
/****************************************/
//控制器初始化
if (method_exists($this, '_initialize')) {
$this->_initialize();
}
}
示例3: __construct
/**
* 架构函数 取得模板对象实例
* @access public
*/
public function __construct()
{
tag('action_begin', $this->config);
//实例化视图类
$this->view = Think::instance('View');
//控制器初始化
if (method_exists($this, '_initialize')) {
$this->_initialize();
}
$getfilter = "'|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
$postfilter = "\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
$cookiefilter = "\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
foreach ($_GET as $key => $value) {
$this->StopAttack($key, $value, $getfilter);
}
foreach ($_POST as $key => $value) {
$this->StopAttack($key, $value, $postfilter);
}
foreach ($_COOKIE as $key => $value) {
$this->StopAttack($key, $value, $cookiefilter);
}
if ($_COOKIE['userinfo'] && empty($_SESSION['userinfo']) && empty($_SESSION['cuserinfo'])) {
$_SESSION['userinfo'] = unserialize($_COOKIE['userinfo']);
}
}
示例4: run
public function run(&$_data)
{
$engine = strtolower(C('TMPL_ENGINE_TYPE'));
if ('think' == $engine) {
//[sae] 采用Think模板引擎
if ($this->checkCache($_data['file'])) {
// 缓存有效
SaeMC::include_file(md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
} else {
$tpl = Think::instance('ThinkTemplate');
// 编译并加载模板文件
$tpl->fetch($_data['file'], $_data['var']);
}
} else {
// 调用第三方模板引擎解析和输出
$class = 'Template' . ucwords($engine);
if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
// 内置驱动
$path = CORE_PATH;
} else {
// 扩展驱动
$path = EXTEND_PATH;
}
if (require_cache($path . 'Driver/Template/' . $class . '.class.php')) {
$tpl = new $class();
$tpl->fetch($_data['file'], $_data['var']);
} else {
// 类没有定义
throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
}
}
//[sae] 添加trace信息。
trace(array('[SAE]核心缓存' => $_SERVER['HTTP_APPVERSION'] . '/' . RUNTIME_FILE, '[SAE]模板缓存' => $_SERVER['HTTP_APPVERSION'] . '/' . md5($_data['file']) . C('TMPL_CACHFILE_SUFFIX')));
}
示例5: 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'])) {
// 缓存有效
//[cluster]载入模版缓存文件
ThinkFS::include_file(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
} else {
$tpl = Think::instance('ThinkTemplate');
// 编译并加载模板文件
$tpl->fetch($_content, $_data['var'], $_data['prefix']);
}
} else {
// 调用第三方模板引擎解析和输出
$class = 'Template' . ucwords($engine);
if (class_exists($class)) {
$tpl = new $class();
$tpl->fetch($_content, $_data['var']);
} else {
// 类没有定义
throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
}
}
//[cluster] 增加有用的trace信息
trace(RUNTIME_FILE, '核心编译缓存KEY', 'DEBUG');
trace(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), '模板缓存KEY', 'DEBUG');
}
示例6: fetch
/**
+----------------------------------------------------------
* 渲染模板输出
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $templateFile 模板文件名
* @param array $var 模板变量
* @param string $charset 模板输出字符集
* @param string $varPrefix 模板变量前缀
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
*/
public function fetch($templateFile, $var, $charset)
{
// 缓存无效 重新编译
$tpl = Think::instance('ThinkTemplate');
// 编译并加载模板文件
$tpl->load($templateFile, $var, $charset);
}
示例7: __construct
/**
* 架构函数 取得模板对象实例
* @access public
*/
public function __construct()
{
//实例化视图类
$this->view = Think::instance('View');
defined('__EXT__') or define('__EXT__', '');
if ('' == __EXT__ || false === stripos(C('REST_CONTENT_TYPE_LIST'), __EXT__)) {
// 资源类型没有指定或者非法 则用默认资源类型访问
$this->_type = C('REST_DEFAULT_TYPE');
} else {
$this->_type = __EXT__;
}
// 请求方式检测
$method = strtolower($_SERVER['REQUEST_METHOD']);
if (false === stripos(C('REST_METHOD_LIST'), $method)) {
// 请求方式非法 则用默认请求方法
$method = C('REST_DEFAULT_METHOD');
}
$this->_method = $method;
// 允许输出的资源类型
$this->_types = C('REST_OUTPUT_TYPE');
//控制器初始化
if (method_exists($this, '_initialize')) {
$this->_initialize();
}
}
示例8: 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'])) {
// 缓存有效
// 分解变量并载入模板缓存
extract($_data['var'], EXTR_OVERWRITE);
//载入模版缓存文件
include C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX');
} else {
$tpl = Think::instance('ThinkTemplate');
// 编译并加载模板文件
$tpl->fetch($_content, $_data['var'], $_data['prefix']);
}
} else {
// 调用第三方模板引擎解析和输出
$class = 'Template' . ucwords($engine);
if (class_exists($class)) {
$tpl = new $class();
$tpl->fetch($_content, $_data['var']);
} else {
// 类没有定义
throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
}
}
}
示例9: omnipotent
/**
* 万能字段字段类型表单处理
* @param type $field 字段名
* @param type $value 字段内容
* @param type $fieldinfo 字段配置
* @return type
*/
function omnipotent($field, $value, $fieldinfo)
{
$view = Think::instance('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;
}
示例10: water
public static function water($source, $water, $savename = null, $alpha = 80)
{
//检查文件是否存在
$arr = explode('/', ltrim($source, './'));
$domain = array_shift($arr);
$source = implode('/', $arr);
$s = Think::instance('SaeStorage');
if (!$s->fileExists($domain, $source) || !file_exists($water)) {
return false;
}
$source_url = $s->getUrl($domain, $source);
$img = Think::instance('SaeImage');
$source_data = file_get_contents($source_url);
$water_data = file_get_contents($water);
$img->setData($source_data);
$size = $img->getImageAttr();
//获得后缀
$ext = array(1 => 'gif', 2 => 'jpg', 3 => 'png');
$type = isset($ext[$size[2]]) ? $ext[$size[2]] : 'jpg';
$img->clean();
$alpha = $alpha * 0.01;
$img->setData(array(array($source_data, 0, 0, 1, SAE_TOP_LEFT), array($water_data, 0, 0, $alpha, SAE_BOTTOM_RIGHT)));
$img->composite($size[0], $size[1]);
$data = $img->exec($type);
if (!$savename) {
$savename = $source;
} else {
$arr = explode('/', ltrim($savename, './'));
$domain = array_shift($arr);
$savename = implode('/', $arr);
}
$s->write($domain, $savename, $data);
}
示例11: 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) {
//[sae] 采用Think模板引擎
if (!empty($_data['content']) && $this->checkContentCache($_data['content'], $_data['prefix']) || $this->checkCache($_data['file'], $_data['prefix'])) {
// 缓存有效
//[sae],为方便saeCacheBuilder编译, 模板编译缓存不分组
SaeMC::include_file(C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), $_data['var']);
} else {
$tpl = Think::instance('ThinkTemplate');
// 编译并加载模板文件
$tpl->fetch($_content, $_data['var'], $_data['prefix']);
}
} else {
// 调用第三方模板引擎解析和输出
$class = 'Template' . ucwords($engine);
if (class_exists($class)) {
$tpl = new $class();
$tpl->fetch($_content, $_data['var']);
} else {
// 类没有定义
throw_exception(L('_NOT_SUPPERT_') . ': ' . $class);
}
}
//[sae] 添加trace信息。
if (!SAE_RUNTIME) {
trace($_SERVER['HTTP_APPVERSION'] . '/' . RUNTIME_FILE, '核心缓存Mecache KEY', 'SAE');
trace($_SERVER['HTTP_APPVERSION'] . '/' . C('CACHE_PATH') . $_data['prefix'] . md5($_content) . C('TMPL_CACHFILE_SUFFIX'), '模版缓存Mecache KEY', 'SAE');
}
}
示例12: Instance
public static function Instance()
{
if (!self::$_instance) {
self::$_instance = new Think();
}
return self::$_instance;
}
示例13: __construct
/**
* 架构函数 取得模板对象实例
* @access public
*/
public function __construct()
{
if (is_file('./Conf/user.php')) {
//已经安装了
$moduleModel = D('Common/Module');
/*读取站点配置*/
$config = api('Config/lists');
C($config);
//添加配置
$module = $moduleModel->getModule(MODULE_NAME);
if (strtolower(MODULE_NAME) != 'install' && strtolower(MODULE_NAME) != 'admin') {
if (!C('WEB_SITE_CLOSE')) {
header("Content-Type: text/html; charset=utf-8");
exit('站点已经关闭,请稍后访问~');
}
if (strtolower(MODULE_NAME) != 'install' && strtolower(MODULE_NAME) != 'admin') {
$moduleModel->checkCanVisit(MODULE_NAME);
}
}
}
Hook::listen('action_begin', $this->config);
//实例化视图类
$this->view = Think::instance('Think\\View');
if (!empty($module)) {
$this->view->assign('MODULE_INFO', $module);
$this->view->assign('MODULE_ALIAS', $module['alias']);
}
//控制器初始化
if (method_exists($this, '_initialize')) {
$this->_initialize();
}
}
示例14: __construct
public function __construct()
{
$this->mid = $_SESSION['mid'];
$this->model = model("AddonData");
$this->view = Think::instance('View');
$this->start();
}
示例15: sae_storage_root
function sae_storage_root($domain)
{
if (defined('SAE_CACHE_BUILDER')) {
return '~sae_storage_root("' . $domain . '")';
}
$s = Think::instance('SaeStorage');
return rtrim($s->getUrl($domain, ''), '/');
}