php think-Controller类(方法)实例源码

下面列出了php think-Controller 类(方法)源码代码实例,从而了解它的用法。

作者:noFloa    项目:cyxbsMobil   
/**
  * CourseController constructor.
  */
 public function __construct()
 {
     // 调用父类控制器
     parent::__construct();
     // 初始化curl管理器
     $this->_curl_init();
 }

作者:novna    项目:meij   
public function __construct()
 {
     /**
      * 如果子类中定义了构造函数则不会隐式调用其父类的构造函数。
      * 如果子类没有定义构造函数则会如同一个普通的类方法一样从父类继承(假如没有被定义为 private 的话)。
      * 因为这子类定义了construct, Controller里面的construct就不会被调用,所以这边要自己继承下父类的construct, 才能用assign
      */
     parent::__construct();
     // 导航栏
     $this->navBar();
     // 作者页不需要
     if (CONTROLLER_NAME != 'Author') {
         // 最新文章
         $this->assign('latestArticles', $this->getArticles('', 10));
         // 最受欢迎 推5
         $this->assign('popularArticles', $this->getArticles('', 10, 0, 5));
         // 关键词列表
         $this->assign('tagsList', $this->tagsList(25));
         $this->assign('randomNum', $this->randomNum(25));
         /**
          * 如果不继承父类的construct(parent::__construct())的话,就不能直接使用assign方法, 但是可以通过__set()间接调用assign, 所以以下写法和用assign效果一样
          * Think\Controller里面有个__set()魔术方法,__set()里面调用assign方法, 因此可通过$object->name = value 的方式来调用__set方法
          * 在给不可访问属性赋值时(类属性为private或者不存在这个属性),__set() 会被调用
          */
         // 随便看看
         $this->randArticles = $this->getArticles('', 10, 0, 0, 0, 1);
         // 浏览历史
         if (CONTROLLER_NAME != 'Index') {
             !empty($_GET['id']) ? $this->recentView(10) : '';
             !empty($_COOKIE['history']) ? $this->history = unserialize($_COOKIE['history']) : '';
             // 当前已浏览过文章的二维数组
         }
     }
 }

作者:torry99    项目:lingsh   
public function __construct()
 {
     parent::__construct();
     $this->_checkAccess();
     $this->serviceConfigList = $this->_getServiceConfigList();
     header("Content-type: text/html; charset=utf-8");
     echo "<style>\n";
     echo "table {margin:0px; padding:0px;}\n";
     echo "table.tbfix {width:100%; table-layout:fixed; background:#bbb}\n";
     echo "table.tbcom {width:100%; background:#bbb}\n";
     echo "td {padding:3px; background:#fff}\n";
     echo "td.title {background:#eee}\n";
     echo "td.left {width:200px}\n";
     echo "input.button {width:100px}\n";
     echo "textarea#result {width:100%; height:300px; background:#ffffe0}";
     echo "</style>";
     echo "<script type='text/javascript' src='/js/jquery.js'></script>\n";
     echo "<script type='text/javascript' src='/js/jquery.form.js'></script>\n";
     echo "<script type='text/javascript' src='/js/app.util.js'></script>\n";
     echo "<script type='text/javascript' src='/js/debug/apiTest.js'></script>\n";
     echo '<h2><a href="/debug/" title="返回首页">API Debug Server</a></h2>';
     echo "<hr/>";
     $user = get_user();
     if ($user) {
         echo '当前登录用户编号:' . $user['uid'], ',用户名:' . $user['uname'];
         echo " | <a href='/debug/apiTest?serviceName=UserController&actionName=login'>切换账号</a>| <a href='/debug/apiTest?serviceName=UserController&actionName=logout'>退出</a>";
     } else {
         echo "<a href='/debug/apiTest?serviceName=UserController&actionName=login'>登录</a>";
     }
     echo "<hr/>";
 }

作者:sea00    项目:wkAdmi   
function __construct()
 {
     parent::__construct();
     //检查 session 是否已经登录
     $users = session('admin_info');
     if ($users) {
         if (md5($users['admin_id'] . C('secret_key')) != $users['secret_key']) {
             session_destroy();
             redirect(U('Public/login'));
             exit;
         }
         $this->admin_id = $users['admin_id'];
         $this->admin_name = $users['admin_name'];
     } else {
         redirect(U('Public/login'));
         exit;
     }
     $this->assign('loginUser', $users);
     /***----------权限控制-----------***/
     $AuthLogic = new \Admin\Logic\AuthLogic($this->admin_id);
     if (true === $AuthLogic->check_auth()) {
     } else {
         if (IS_AJAX) {
             $this->error('没有操作权限');
             exit;
         } else {
             showmessage('没有该页面权限');
             exit;
         }
     }
 }

作者:cassileSh    项目:ebxz   
public function __construct()
 {
     parent::__construct();
     if (!$_SESSION['user']) {
         header('location:' . U('admin/Index/login'));
     }
 }

作者:kls    项目:kldn   
function __construct()
 {
     $this->pdo = new PdoHelper();
     parent::__construct();
     $this->loadWebConfig();
     $this->getLoginuUser();
 }

作者:Hisheng    项目:Heyso   
function __construct()
 {
     parent::__construct();
     //if(empty($_SESSION['USER_ID']))exit(C('SITE_LANG.LOGIN_ALERT'));//check login
     $this->visible_tag_model = D('VisibleTag');
     $this->follow_model = D('Follow');
 }

作者:sayi21c    项目:CarService-ServerSid   
public function __construct()
 {
     $this->jsonUtils = new \Org\Util\JsonUtils();
     $this->session_handle = new \Org\Util\SessionHandle();
     $this->dao = M('service');
     parent::__construct();
 }

作者:noiki    项目:baomihu   
public function __construct()
 {
     parent::__construct();
     //读取配置信息
     $web_stting = F('setting');
     if ($web_stting === false) {
         $params = array();
         $list = M('Setting')->getField('name,value');
         foreach ($list as $key => $val) {
             $params[$key] = unserialize($val) ? unserialize($val) : $val;
         }
         F('setting', $params);
         $web_stting = F('setting');
     }
     $this->assign('web_stting', $web_stting);
     //站点状态判断
     if ($web_stting['site_status'] != 1) {
         echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
         echo $web_stting['closed_reason'];
         exit;
     } else {
         $this->check_login();
         $link = M('Link')->where(array('status' => 1))->order('sort DESC')->select();
         $this->assign('link', $link);
         $this->assign('seo', seo());
     }
 }

作者:hiden    项目:thinksho   
public function __construct()
 {
     parent::__construct();
     $this->mkCateData();
     $this->getNav();
     $this->getCategoryTree();
 }

作者:vipfo    项目:bm   
function __construct()
 {
     parent::__construct();
     if (empty($_COOKIE['USERNAME'])) {
         //$this->success('', '?c=user&a=login');
     }
 }

作者:andychang8    项目:fuzhuang.erp.co   
public function __construct()
 {
     parent::__construct();
     if (!empty($this->controll_keywords)) {
         $this->model = D($this->controll_keywords);
     }
     $this->system_name = "兔芭露<span style='vertical-align:super; font-size:9px'>TM</span>产销存管理系统";
     $this->page_title = "RMS";
     $this->brand = C('brand');
     $this->brand_lang = C('brand_lang');
     $this->retailer_products_status = C('retailer_products_status');
     $this->plans_status = C('plans_status');
     $this->retailers = D('Retailer')->getRetailers();
     $this->retailer_id_selected = (int) I('get.retailer_id');
     $this->retailer_payment_status = C('retailer_payment_status');
     $this->retailer_payment_status_selected = (int) I('get.retailer_payment_status');
     $this->retailer_apply_status = C('retailer_apply_status');
     $this->retailer_apply_status_selected = (int) I('get.retailer_apply_status');
     $this->bill_status = C('retailer_bill_status');
     $this->bill_status_selected = (int) I('get.bill_status');
     $this->initSubMenus();
     $this->CONTROLLER_NAME = CONTROLLER_NAME;
     $this->ACTION_NAME = ACTION_NAME;
     $notices = D('articles')->getArticles(array(), 5);
     $this->notices = $notices['data'];
 }

作者:dongsongson    项目:vuejs-hu   
public function __construct()
 {
     parent::__construct();
     if (ACTION_NAME != "login" && ACTION_NAME != "code" && ACTION_NAME != "check_verify") {
         $this->check();
     }
 }

作者:haolj    项目:wstmal   
public function __construct()
 {
     parent::__construct();
     //初始化系统信息
     $m = D('Home/System');
     $GLOBALS['CONFIG'] = $m->loadConfigs();
     $this->assign("baseUser", $_SESSION['USER']);
     $areas = D('Home/Areas');
     $areaList = $areas->getCitys();
     $areaId2 = $this->getDefaultCity();
     $currArea = $areas->getArea($areaId2);
     $this->assign('template_path', $template_path);
     //获取分类
     $gcm = D('Home/GoodsCats');
     $catList = $gcm->getGoodsCats($areaId2);
     $spm = D('Home/Shops');
     $selfShop = $spm->getSelfShop($areaId2);
     $this->assign('selfShop', $selfShop);
     $m = D('Home/Cart');
     $cartInfo = $m->getCartInfo();
     $this->assign('cartcnt', count($cartInfo["cartgoods"]));
     $this->assign('searchType', I("searchType", 1));
     $this->assign('catList', $catList);
     $this->assign('currCity', $areaList[$areaId2]);
     $this->assign('cityList', $areaList);
     $this->assign('areaId2', $areaId2);
     $this->assign('currArea', $currArea);
     $this->assign('CONF', $GLOBALS['CONFIG']);
     $this->header();
     //加入头部
     $this->footer();
     //加入底部
 }

作者:Hisheng    项目:Heyso   
function __construct()
 {
     parent::__construct();
     //if(empty($_SESSION['USER_ID']))exit(C('SITE_LANG.LOGIN_ALERT'));//check login
     $this->user_model = D('User');
     $this->user_config_model = D('UserConfig');
 }

作者:PieHus    项目:embahus   
public function __construct()
 {
     parent::__construct();
     if (!session('?username')) {
         $this->error('请先登录', U('login/login'), 3);
     }
 }

作者:Hisheng    项目:Heyso   
function __construct()
 {
     parent::__construct();
     //if(empty($_SESSION['USER_ID']))exit(C('SITE_LANG.LOGIN_ALERT'));//check login
     $this->comment_model = D('Comment');
     $this->piece_comment_model = D('PieceComment');
 }

作者:28354148    项目:kaixinwa2.   
function __construct()
 {
     parent::__construct();
     $this->room = D("Room");
     $this->room_type = D("Room_type");
     $this->lunbo = D("Lunbo");
 }

作者:highestgoodlikewate    项目:admin.28.co   
public function __construct()
 {
     parent::__construct();
     if (!session('id')) {
         $this->error('必须先登录', U('Login/index'));
     }
 }

作者:leifuchen011    项目:compan   
public function __construct()
 {
     parent::__construct();
     R('Tool/Too/chechLogin');
     R('Home/Public/showHeader');
     R('Home/Public/showFooter');
 }


问题


面经


文章

微信
公众号

扫码关注公众号