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


PHP Hook::add方法代碼示例

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


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

示例1: run

 public function run(&$parms)
 {
     //安裝時不執行
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     $data = S('global_hooks');
     if (!$data) {
         $hooks = M('Hooks', "common_")->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('Addons', "common_")->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('global_hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
開發者ID:h136799711,項目名稱:baseItboye,代碼行數:26,代碼來源:InitHookBehavior.class.php

示例2: run

 /**
  * @param mixed $content
  */
 public function run(&$content)
 {
     /**
      *  //真不知道說什麽好。。。
      *      這裏      原因是tp 不能把tag放在項目配置中,隻能放在common中,而common模塊先於install 初始化
      *     so。。。。。
      *
      */
     if (C('DB_TYPE') == 'GreenCMS_DB_TYPE') {
     } else {
         if (isset($_GET['m']) && strtolower($_GET['m']) == 'install') {
             return;
         }
         $data = S('hooks');
         if (!$data) {
             $hooks = M('Hooks')->getField('name,addons');
             foreach ($hooks as $key => $value) {
                 if ($value) {
                     $map['status'] = 1;
                     $names = explode(',', $value);
                     $map['name'] = array('IN', $names);
                     $data = M('Addons')->where($map)->getField('id,name');
                     if ($data) {
                         $addons = array_intersect($names, $data);
                         Hook::add($key, $addons);
                     }
                 }
             }
             S('hooks', Hook::get());
         } else {
             Hook::import($data, false);
         }
     }
 }
開發者ID:zachdary,項目名稱:GreenCMS,代碼行數:37,代碼來源:InitHookBehavior.class.php

示例3: run

 public function run(&$content)
 {
     if (isset($_GET['m']) && $_GET['m'] === 'Install') {
         return;
     }
     $data = S('hooks');
     if (!$data) {
         $hooks = M('Hooks')->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('Addons')->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
開發者ID:Willshon,項目名稱:OLCS,代碼行數:25,代碼來源:InitHookBehavior.class.php

示例4: run

 public function run(&$content)
 {
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     $data = S('hooks');
     if (!$data) {
         $hooks = M('hooks')->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = (array) M('addons')->where($map)->getField('id,name');
                 $data_plugin = (array) M('plugin')->where($map)->getField('id,name');
                 $data = array_merge($data, $data_plugin);
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
開發者ID:yxz1025,項目名稱:weiphp3.0,代碼行數:27,代碼來源:InitHookBehavior.class.php

示例5: run

 /**
  * 行為擴展的執行入口必須是run
  * @author jry <598821125@qq.com>
  */
 public function run(&$content)
 {
     // 安裝模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 添加插件配置
     $addon_config['ADDON_PATH'] = './Addons/';
     $addon_config['AUTOLOAD_NAMESPACE'] = C('AUTOLOAD_NAMESPACE');
     $addon_config['AUTOLOAD_NAMESPACE']['Addons'] = $addon_config['ADDON_PATH'];
     C($addon_config);
     $data = S('hooks');
     if (!$data || APP_DEBUG === true) {
         $hooks = D('Admin/Hook')->getField('name,addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = D('Admin/Addon')->where($map)->getField('id,name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
開發者ID:applemin,項目名稱:tangguo,代碼行數:35,代碼來源:InitHookBehavior.class.php

示例6: run

 public function run(&$content)
 {
     if (!file_exist(UPLOAD_PATH . 'install.lock')) {
         return true;
     }
     $data = S('common_behavior_hooks');
     if (!$data) {
         $hooks = M('hooks')->where(array('status' => 1))->getField('name, addons');
         foreach ($hooks as $key => $value) {
             if ($value) {
                 $map['status'] = 1;
                 $names = explode(',', $value);
                 $map['name'] = array('IN', $names);
                 $data = M('addons')->where($map)->getField('id, name');
                 if ($data) {
                     $addons = array_intersect($names, $data);
                     Hook::add($key, array_map('get_addon_class', $addons));
                 }
             }
         }
         S('common_behavior_hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
開發者ID:easytp,項目名稱:easytp,代碼行數:25,代碼來源:InitHookBehavior.class.php

示例7: testRun

 public function testRun()
 {
     Hook::add('my_pos', '\\tests\\thinkphp\\library\\think\\behavior\\One');
     Hook::add('my_pos', ['\\tests\\thinkphp\\library\\think\\behavior\\Two']);
     Hook::add('my_pos', '\\tests\\thinkphp\\library\\think\\behavior\\Three', true);
     $data['id'] = 0;
     $data['name'] = 'thinkphp';
     Hook::listen('my_pos', $data);
     $this->assertEquals(2, $data['id']);
     $this->assertEquals('thinkphp', $data['name']);
     $this->assertEquals(['\\tests\\thinkphp\\library\\think\\behavior\\Three', '\\tests\\thinkphp\\library\\think\\behavior\\One', '\\tests\\thinkphp\\library\\think\\behavior\\Two'], Hook::get('my_pos'));
 }
開發者ID:Lofanmi,項目名稱:think,代碼行數:12,代碼來源:hookTest.php

示例8: PostComment

 /**
  * @todo: 發送評論
  * @author Saki <ilulu4ever816@gmail.com>
  * @date 2014-12-22 上午9:34:18
  * @version V1.0
  */
 public function PostComment()
 {
     $model = new \Admin\Model\ArticleCommentModel();
     $post = $_POST['ArticleComment'];
     $id = $post['aid'];
     $comment_id = $model->createComment($post);
     //發送郵件,這裏為遊客發送評論,則為管理員郵箱收到郵件
     if ($comment_id) {
         \Think\Hook::listen('postComment', $comment_id);
         \Think\Hook::add('postComment', 'Home\\Behaviors\\emailBehavior');
     }
     $this->redirect('Article/view', array('id' => $id, 'p' => 1));
 }
開發者ID:bushijie,項目名稱:500efuma,代碼行數:19,代碼來源:ArticleController.class.php

示例9: app_init

 public function app_init()
 {
     $bags = self::$tags;
     foreach ($bags as $hook => $classes) {
         foreach ($classes as $class) {
             $tags = Hook::get($hook);
             if (class_exists($class)) {
                 if (!array_search($class, $tags)) {
                     Hook::add($hook, $class);
                 }
             }
         }
     }
 }
開發者ID:snowair,項目名稱:think-hookagent,代碼行數:14,代碼來源:HookAgent.php

示例10: PostComment

 /**
  * @todo: 發送評論-後台管理員發送
  * @author Saki <ilulu4ever816@gmail.com>
  * @date 2014-12-22 上午9:34:18
  * @version V1.0
  */
 public function PostComment()
 {
     $model = new \Admin\Model\ArticleCommentModel();
     $post = $_POST['ArticleComment'];
     $id = $post['aid'];
     $admin_info = $this->admin_info;
     $post['is_admin'] = $admin_info['id'];
     $comment_id = $model->createComment($post);
     if ($comment_id) {
         \Think\Hook::listen('postComment', $comment_id);
         \Think\Hook::add('postComment', 'Home\\Behaviors\\emailBehavior');
     }
     $this->redirect('ArticleList/view', array('id' => $id, 'p' => 1));
 }
開發者ID:bushijie,項目名稱:500efuma,代碼行數:20,代碼來源:ArticleCommentController.class.php

示例11: run

 public function run(&$content)
 {
     if (isset($_GET['g']) && strtolower($_GET['g']) === 'install') {
         return;
     }
     $data = S('hooks');
     if (!$data) {
         is_array($plugins = M('Plugins')->where("status=1")->getField("name,hooks")) ? null : ($plugins = array());
         foreach ($plugins as $plugin => $hooks) {
             if ($hooks) {
                 $hooks = explode(",", $hooks);
                 foreach ($hooks as $hook) {
                     Hook::add($hook, $plugin);
                 }
             }
         }
         S('hooks', Hook::get());
     } else {
         Hook::import($data, false);
     }
 }
開發者ID:Njupt-Sast-Network,項目名稱:UMR,代碼行數:21,代碼來源:InitHookBehavior.class.php

示例12: hookAction

 public function hookAction()
 {
     Hook::add('ad', 'Behavior\\adBehavior');
     //添加一個行為鉤子
     $this->display();
 }
開發者ID:ndflydog,項目名稱:thinkphp_rbac_pjax,代碼行數:6,代碼來源:TeController.class.php

示例13: run

 /**
  * 行為擴展的執行入口必須是run
  * @author jry <598821125@qq.com>
  */
 public function run(&$content)
 {
     // 安裝模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 如果是後台並且不是Admin模塊則設置默認控製器層為Admin
     if (MODULE_MARK === 'Admin' && MODULE_NAME !== 'Admin') {
         $oc_config['DEFAULT_C_LAYER'] = 'Admin';
     }
     // 當前模塊模版參數配置
     $oc_config['TMPL_PARSE_STRING'] = C('TMPL_PARSE_STRING');
     // 先取出配置文件中定義的否則會被覆蓋
     $oc_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/img';
     $oc_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/css';
     $oc_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/js';
     $oc_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/libs';
     // 獲取當前主題的名稱
     $current_theme = D('Admin/Theme')->where(array('current' => 1))->order('id asc')->getField('name');
     if ($current_theme) {
         // 前台Home模塊靜態資源路徑及模板繼承基本模板
         $home_public_path = './Theme/' . $current_theme . '/Home/Public';
         if (is_dir($home_public_path)) {
             $oc_config['HOME_PUBLIC_LAYOUT'] = $home_public_path . '/layout.html';
             $oc_config['TMPL_PARSE_STRING']['__HOME_IMG__'] = __ROOT__ . '/' . $home_public_path . '/img';
             $oc_config['TMPL_PARSE_STRING']['__HOME_CSS__'] = __ROOT__ . '/' . $home_public_path . '/css';
             $oc_config['TMPL_PARSE_STRING']['__HOME_JS__'] = __ROOT__ . '/' . $home_public_path . '/js';
             $oc_config['TMPL_PARSE_STRING']['__HOME_LIBS__'] = __ROOT__ . '/' . $home_public_path . '/libs';
         }
         // 如果當前主題存在User模板則改變相關配置
         if (is_dir('./Theme/' . $current_theme . '/User')) {
             $oc_config['USER_CENTER_SIDE'] = './Theme/' . $current_theme . '/User/Index/side.html';
             $oc_config['USER_CENTER_FORM'] = './Theme/' . $current_theme . '/User/Builder/form.html';
             $oc_config['USER_CENTER_LIST'] = './Theme/' . $current_theme . '/User/Builder/list.html';
             $oc_config['USER_LOGIN_MODAL'] = './Theme/' . $current_theme . '/User/User/login_modal.html';
         }
         // 當前主題
         $current_theme_path = './Theme/' . $current_theme . '/' . MODULE_NAME . '/';
         //當前主題文件夾路徑
         if (is_dir($current_theme_path)) {
             if (MODULE_MARK === 'Home') {
                 $oc_config['VIEW_PATH'] = $current_theme_path;
             }
             $oc_config['CURRENT_THEME'] = $current_theme;
             //默認主題設為當前主題
             // 各模塊自帶靜態資源路徑
             $module_public_path = './Theme/' . $current_theme . '/' . MODULE_NAME . '/Public';
             if (is_dir($module_public_path)) {
                 $oc_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . $module_public_path . '/img';
                 $oc_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . $module_public_path . '/css';
                 $oc_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . $module_public_path . '/js';
                 $oc_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . $module_public_path . '/libs';
             }
         }
     }
     C($oc_config);
     // 添加配置
     // 讀取數據庫中的配置
     $system_config = S('DB_CONFIG_DATA');
     if (!$system_config) {
         // 獲取所有係統配置
         $system_config = D('Admin/Config')->lists();
         // SESSION與COOKIE與前綴設置避免衝突
         $system_config['SESSION_PREFIX'] = ENV_PRE . MODULE_MARK . '_';
         // Session前綴
         $system_config['COOKIE_PREFIX'] = ENV_PRE . MODULE_MARK . '_';
         // Cookie前綴
         // 獲取所有安裝的模塊配置
         $module_list = D('Admin/Module')->where(array('status' => '1'))->select();
         foreach ($module_list as $val) {
             $module_config[strtolower($val['name'] . '_config')] = json_decode($val['config'], true);
             $module_config[strtolower($val['name'] . '_config')]['module_name'] = $val['name'];
         }
         if ($module_config) {
             // 合並模塊配置
             $system_config = array_merge($system_config, $module_config);
             // 加載模塊標簽庫及行為擴展
             $system_config['TAGLIB_PRE_LOAD'] = explode(',', C('TAGLIB_PRE_LOAD'));
             // 先取出配置文件中定義的否則會被覆蓋
             foreach ($module_config as $key => $val) {
                 // 加載模塊標簽庫
                 if ($val['taglib']) {
                     foreach ($val['taglib'] as $tag) {
                         $tag_path = APP_PATH . $val['module_name'] . '/' . 'TagLib' . '/' . $tag . '.class.php';
                         if (is_file($tag_path)) {
                             $system_config['TAGLIB_PRE_LOAD'][] = $val['module_name'] . '\\TagLib\\' . $tag;
                         }
                     }
                 }
                 // 加載模塊行為擴展
                 if ($val['behavior']) {
                     foreach ($val['behavior'] as $bhv) {
                         $bhv_path = APP_PATH . $val['module_name'] . '/' . 'Behavior' . '/' . $bhv . 'Behavior.class.php';
                         if (is_file($bhv_path)) {
                             \Think\Hook::add('corethink_behavior', $val['module_name'] . '\\Behavior\\' . $bhv . 'Behavior');
                         }
//.........這裏部分代碼省略.........
開發者ID:lipeng-github,項目名稱:corethink,代碼行數:101,代碼來源:InitConfigBehavior.class.php

示例14: S

    $ssidarr = S("ssid_" . $ssid);
    if (!$ssidarr) {
        return;
    }
    if (!isset($ssidarr['session_die_time']) or $ssidarr['session_die_time'] > time()) {
        S("ssid_" . $_GET['ssid'], false);
        return;
    }
    foreach ($ssidarr as $k => $v) {
        \think\Session::set($k, $v);
    }
});
\think\Hook::add("app_end", function () {
    if (isset($_GET['ssid'])) {
        if (isset($_SESSION)) {
            S("ssid_" . $_GET['ssid'], $_SESSION);
        }
    }
});
function system_error($k)
{
    header("Content-type: application/json");
    $system_error = C("system_error");
    echo json_encode($system_error[$k]);
    die;
}
function throw_out($k)
{
    header("Content-type: application/json");
    $error = C("error");
    $error = $error[CONTROLLER_NAME . "_" . ACTION_NAME];
開發者ID:LoveOyy,項目名稱:woaini,代碼行數:31,代碼來源:common.php

示例15: run

 /**
  * 行為擴展的執行入口必須是run
  * @author jry <598821125@qq.com>
  */
 public function run(&$content)
 {
     // 安裝模式下直接返回
     if (defined('BIND_MODULE') && BIND_MODULE === 'Install') {
         return;
     }
     // 數據緩存前綴
     // 獲取ThinkPHP控製器分級時控製器名稱
     $controller_name = explode('/', CONTROLLER_NAME);
     if (sizeof($controller_name) === 2) {
         C('DATA_CACHE_PREFIX', ENV_PRE . MODULE_NAME . '_' . $controller_name[0] . '_');
     } else {
         C('DATA_CACHE_PREFIX', ENV_PRE . MODULE_NAME . '_');
     }
     // 讀取數據庫中的配置
     $system_config = S('DB_CONFIG_DATA');
     if (!$system_config) {
         // 獲取所有係統配置
         $system_config = D('Admin/Config')->lists();
         // 獲取所有安裝的模塊配置
         $module_list = D('Admin/Module')->where(array('status' => '1'))->select();
         foreach ($module_list as $val) {
             $module_config[strtolower($val['name'] . '_config')] = json_decode($val['config'], true);
             $module_config[strtolower($val['name'] . '_config')]['module_name'] = $val['name'];
         }
         if ($module_config) {
             // 合並模塊配置
             $system_config = array_merge($system_config, $module_config);
             // 加載模塊標簽庫及行為擴展
             $system_config['TAGLIB_PRE_LOAD'] = explode(',', C('TAGLIB_PRE_LOAD'));
             // 先取出配置文件中定義的否則會被覆蓋
             foreach ($module_config as $key => $val) {
                 // 加載模塊標簽庫
                 if ($val['taglib']) {
                     foreach ($val['taglib'] as $tag) {
                         $system_config['TAGLIB_PRE_LOAD'][] = $val['module_name'] . '\\TagLib\\' . $tag . '';
                     }
                 }
                 // 加載模塊行為擴展
                 if ($val['behavior']) {
                     foreach ($val['behavior'] as $bhv) {
                         \Think\Hook::add('corethink_behavior', $val['module_name'] . '\\Behavior\\' . $bhv . 'Behavior');
                     }
                 }
             }
             $system_config['TAGLIB_PRE_LOAD'] = implode(',', $system_config['TAGLIB_PRE_LOAD']);
         }
         // 獲取當前主題的名稱
         $current_theme = D('Admin/Theme')->where(array('current' => 1))->order('id asc')->find();
         // 當前模塊模版參數配置
         $system_config['TMPL_PARSE_STRING'] = C('TMPL_PARSE_STRING');
         // 先取出配置文件中定義的否則會被覆蓋
         $system_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/img';
         $system_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/css';
         $system_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/js';
         $system_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . APP_PATH . MODULE_NAME . '/View/Public/libs';
         if ($current_theme) {
             $current_theme['module'] = explode(',', $current_theme['module']);
             $current_theme['module'][] = 'Home';
             // 強製支持主題對Home的支持
             // 一旦開啟主題那麽前台必須啟用主題相關模版(後台無需支持主題)
             $theme_public_path = './Theme/' . $current_theme['name'] . '/Home/Public';
             if (is_dir($theme_public_path)) {
                 $system_config['TMPL_PARSE_STRING']['__HOME_IMG__'] = __ROOT__ . '/' . $theme_public_path . '/img';
                 $system_config['TMPL_PARSE_STRING']['__HOME_CSS__'] = __ROOT__ . '/' . $theme_public_path . '/css';
                 $system_config['TMPL_PARSE_STRING']['__HOME_JS__'] = __ROOT__ . '/' . $theme_public_path . '/js';
                 $system_config['TMPL_PARSE_STRING']['__HOME_LIBS__'] = __ROOT__ . '/' . $theme_public_path . '/libs';
             }
             // 如果啟用的主題配置裏勾選了當前模塊那麽當前模塊啟用主題相關模版否則仍啟用係統模版
             if (in_array(MODULE_NAME, $current_theme['module'])) {
                 $system_config['CURRENT_THEME'] = $current_theme['name'];
                 // 設置當前主題
                 $theme_public_path = './Theme/' . $current_theme['name'] . '/' . MODULE_NAME . '/Public';
                 $theme_wap_path = './Theme/' . $current_theme['name'] . '/' . MODULE_NAME . '/wap';
                 if (is_dir($theme_public_path)) {
                     $system_config['TMPL_PARSE_STRING']['__IMG__'] = __ROOT__ . '/' . $theme_public_path . '/img';
                     $system_config['TMPL_PARSE_STRING']['__CSS__'] = __ROOT__ . '/' . $theme_public_path . '/css';
                     $system_config['TMPL_PARSE_STRING']['__JS__'] = __ROOT__ . '/' . $theme_public_path . '/js';
                     $system_config['TMPL_PARSE_STRING']['__LIBS__'] = __ROOT__ . '/' . $theme_public_path . '/libs';
                 }
                 // 判斷是否含有wap專用模版
                 if (is_dir($theme_wap_path)) {
                     $system_config['HAS_WAP'] = 'wap';
                 }
             }
         } else {
             // 判斷是否含有wap專用模版
             if (sizeof($controller_name) === 2) {
                 if (is_dir(APP_PATH . MODULE_NAME . '/View/Home/wap')) {
                     $system_config['HAS_WAP'] = 'wap';
                 }
             } else {
                 if (is_dir(APP_PATH . MODULE_NAME . '/View/wap')) {
                     $system_config['HAS_WAP'] = 'wap';
                 }
             }
//.........這裏部分代碼省略.........
開發者ID:hujun123qwe,項目名稱:plover,代碼行數:101,代碼來源:InitConfigBehavior.class.php


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