本文整理匯總了PHP中think\Hook::listen方法的典型用法代碼示例。如果您正苦於以下問題:PHP Hook::listen方法的具體用法?PHP Hook::listen怎麽用?PHP Hook::listen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Hook
的用法示例。
在下文中一共展示了Hook::listen方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _initialize
/**
* 初始化方法
* @author jry <598821125@qq.com>
*/
protected function _initialize()
{
// 係統開關
if (!C('TOGGLE_WEB_SITE')) {
$this->error('站點已經關閉,請稍後訪問~');
}
// 獲取所有模塊配置的用戶導航
$mod_con['status'] = 1;
$_user_nav_main = array();
$_user_nav_list = D('Admin/Module')->where($mod_con)->getField('user_nav', true);
foreach ($_user_nav_list as $key => $val) {
if ($val) {
$val = json_decode($val, true);
if ($val['main']) {
$_user_nav_main = array_merge($_user_nav_main, $val['main']);
}
}
}
// 監聽行為擴展
\Think\Hook::listen('corethink_behavior');
$this->assign('meta_keywords', C('WEB_SITE_KEYWORD'));
$this->assign('meta_description', C('WEB_SITE_DESCRIPTION'));
$this->assign('_new_message', cookie('_new_message'));
// 獲取用戶未讀消息數量
$this->assign('_user_auth', session('user_auth'));
// 用戶登錄信息
$this->assign('_user_nav_main', $_user_nav_main);
// 用戶導航信息
$this->assign('_user_center_side', C('USER_CENTER_SIDE'));
// 用戶中心側邊
$this->assign('_user_login_modal', C('USER_LOGIN_MODAL'));
// 用戶登錄彈窗
$this->assign('_home_public_layout', C('HOME_PUBLIC_LAYOUT'));
// 頁麵公共繼承模版
}
示例2: detail
/**
* 查詢指定分類的詳細信息
* @param int $info detail 查詢的 id 或者slug
*/
public function detail($info = 1)
{
if (get_opinion("auto_channel", false, false)) {
$this->channel($info);
Hook::listen('app_end');
die;
}
$CatsLogic = new CatsLogic();
$PostsLogic = new PostsLogic();
$cat = $CatsLogic->detail($info);
//
$this->assign('cat_id', $cat['cat_id']);
// 賦值數據集
$this->if404($cat, "非常抱歉,沒有這個分類,可能它已經躲起來了");
//優雅的404
$posts_id = $CatsLogic->getPostsId($cat['cat_id']);
$count = sizeof($posts_id);
$count == 0 ? $res404 = 0 : ($res404 = 1);
if (!empty($posts_id)) {
$Page = new GreenPage($count, get_opinion('PAGER'));
$pager_bar = $Page->show();
$limit = $Page->firstRow . ',' . $Page->listRows;
$posts_list = $PostsLogic->getList($limit, 'single', 'post_date desc', true, array(), $posts_id);
}
$this->assign('title', '分類 ' . $cat['cat_name'] . ' 所有文章');
// 賦值數據集
$this->assign('res404', $res404);
$this->assign('postslist', $posts_list);
// 賦值數據集
$this->assign('pager', $pager_bar);
// 賦值分頁輸出
$this->assign('breadcrumbs', get_breadcrumbs('cats', $cat['cat_id']));
$this->display('Archive/single-list');
}
示例3: _initialize
/**
* 初始化方法
* @author jry <598821125@qq.com>
*/
protected function _initialize()
{
// 係統開關
if (!C('TOGGLE_WEB_SITE')) {
$this->error('站點已經關閉,請稍後訪問~');
}
// 獲取所有模塊配置的用戶導航
$mod_con['status'] = 1;
$_user_nav_main = array();
$_user_nav_list = D('Admin/Module')->where($mod_con)->getField('user_nav', true);
foreach ($_user_nav_list as $key => $val) {
if ($val) {
$val = json_decode($val, true);
$_user_nav_main = array_merge($_user_nav_main, $val['main']);
}
}
// 監聽行為擴展
\Think\Hook::listen('corethink_behavior');
$this->assign('meta_keywords', C('WEB_SITE_KEYWORD'));
$this->assign('meta_description', C('WEB_SITE_DESCRIPTION'));
$this->assign('_new_message', cookie('_new_message'));
// 獲取用戶未讀消息數量
$this->assign('_user_auth', session('user_auth'));
// 用戶登錄信息
$this->assign('_user_nav_main', $_user_nav_main);
// 用戶導航信息
}
示例4: send
/**
* 發送數據到客戶端
* @access public
* @param mixed $data 數據
* @param string $type 返回類型
* @param bool $return 是否返回數據
* @return mixed
*/
public function send($data = [], $type = '', $return = false)
{
if ('' == $type) {
$type = $this->type ?: (IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'));
}
$type = strtolower($type);
$data = $data ?: $this->data;
if (!headers_sent() && isset($this->contentType[$type])) {
header('Content-Type:' . $this->contentType[$type] . '; charset=utf-8');
}
if (is_callable($this->transform)) {
$data = call_user_func_array($this->transform, [$data]);
} else {
switch ($type) {
case 'json':
// 返回JSON數據格式到客戶端 包含狀態信息
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
break;
case 'jsonp':
// 返回JSON數據格式到客戶端 包含狀態信息
$handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler');
$data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');';
break;
}
}
APP_HOOK && Hook::listen('return_data', $data);
if ($return) {
return $data;
}
echo $data;
$this->isExit() && exit;
}
示例5: testImport
public function testImport()
{
Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\One', '\\tests\\thinkphp\\library\\think\\behavior\\Three']]);
Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\Two']], false);
Hook::import(['my_pos' => ['\\tests\\thinkphp\\library\\think\\behavior\\Three', '_overlay' => true]]);
$data['id'] = 0;
$data['name'] = 'thinkphp';
Hook::listen('my_pos', $data);
$this->assertEquals(3, $data['id']);
}
示例6: SmsReady
public function SmsReady($mobile, $content)
{
$mobileids = $mobile . date('YmdHis');
$result = self::sendSMS($mobile, $content, $mobileids);
if ($result != true) {
\Think\Hook::listen('HomeLog', $parm = array('function' => 'SendSmsModel::SmsReady -> $result', 'logmsg' => 'result is false, ' . "{$result}", 'level' => 'ALERT'));
return false;
}
return true;
}
示例7: GetUsers
public function GetUsers($UsersId, $Feild)
{
$where['userid'] = array('IN', $UsersId);
$result = self::where($where)->field($Feild)->select();
if ($result !== false) {
return $result;
} else {
\Think\Hook::listen('HomeLog', $parm = array('function' => 'GetUsers -> $result', 'logmsg' => 'result is false', 'level' => 'ALERT'));
}
}
示例8: error404
/**
* 顯示404頁
* @function 404 ERROR 需要顯示錯誤的信息
*
* @param string $message
*/
public function error404($message = "非常抱歉,你需要的頁麵暫時不存在,可能它已經躲起來了。.")
{
$this->assign("message", $message);
if (File::file_exists(T('Home@Index/404'))) {
$this->display('Index/404');
} else {
$this->show($message);
}
Hook::listen('app_end');
die;
}
示例9: BlackNew
public function BlackNew($RecordId, $UserId)
{
$data = array('recordid' => $RecordId, 'userid' => $UserId, 'lasttime' => time());
$result = self::add($data);
if ($result !== false) {
return true;
} else {
return false;
\Think\Hook::listen('HomeLog', $parm = array('function' => 'BlackNew -> $result', 'logmsg' => 'result is false', 'level' => 'ALERT'));
}
}
示例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'];
$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));
}
示例11: ajax_add
public function ajax_add(&$json)
{
$offset = I('offset');
$data['content'] = I('content');
Hook::listen('hy_filter', $data['content']);
$data['user_id'] = ss_uid();
$data['create_time'] = time();
$data['anonymous'] = 0;
if (false === $this->add($data)) {
return $json['info'] = $this->getError();
}
$json['status'] = true;
$json['data'] = $this->lists($offset);
}
示例12: 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));
}
示例13: customConfig
/**
* 用戶存放在數據庫中的配置,覆蓋config中的
*/
function customConfig()
{
$customConfig = S('customConfig');
if ($customConfig && APP_Cache) {
$options = $customConfig;
} else {
$options = D('Options')->where(array('autoload' => 'yes'))->select();
if (APP_Cache) {
S('customConfig', $options);
}
}
foreach ($options as $config) {
C($config['option_name'], $config['option_value']);
}
Hook::listen('base_customConfig');
}
示例14: _initialize
/**
* 初始化方法
* @author jry <598821125@qq.com>
*/
protected function _initialize()
{
// 係統開關
if (!C('TOGGLE_WEB_SITE')) {
$this->error('站點已經關閉,請稍後訪問~');
}
// 監聽行為擴展
try {
\Think\Hook::listen('corethink_behavior');
} catch (\Exception $e) {
file_put_contents(RUNTIME_PATH . 'error.json', json_encode($e->getMessage()));
}
// 記錄當前url
if (MODULE_NAME !== 'User' && IS_GET === true) {
cookie('forward', (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"]);
}
}
示例15: _empty
/**
* 顯示首頁為空時
* @param $method
* @param $args
*/
public function _empty($method, $args)
{
Hook::listen('home_index_empty');
}