zoukankan      html  css  js  c++  java
  • thinkphp3.2.2前后台公用类架构问题

    3.13之前好多项目都使用前后台公用类,在lib/action下创建Baseaction做为公共继承类,发现3.2.2里面很多人都用A调用,这样每用一次要用A调用,好麻烦,小编特意偷懒。亲测使用以下方法解决。欢迎加强

    thinkphp3.2.2的这么创建Application/Common/Controller/BaseController.class.php

     1 <?php
     2 namespace CommonController;
     3 use ThinkController;
     4     /**
     5     * 前后台公用基类
     6     * modify author : Jack
     7     * modify time : 2014-7-12
     8     */
     9     class BaseController extends Controller{
    10         
    11         public function _initialize() {//全局变量
    12                dump('基类');
    13             $this->cfg();
    14         }
    15      }

    在Home/Controller/ZixunController.class.php中

    <?php
    namespace HomeController;
    use CommonControllerBaseController;
    class ZixunController extends BaseController {
    
        public function index() {
            $result = $this->lists();
            dump($result);
        }
    }

          当然,在前后台还可以创建自己的基类,比如后台建AdminController.class.php继承BaseController.class.php,前台创建HomeController.class.php继承BaseController.class.php各自模块继承各自的基类,这样项目可以更清晰,可以避免重复造轮子,省很多事情,但是必须注意的是每个类必须声明命名空间,但是使用的资源可以在各自的基类中定义之后后面不用在写一次。比如AdminController.class.php继承BaseController.class.php,就不用再写use ThinkController了,直接使用use CommonControllerBaseController就可以了。

  • 相关阅读:
    处理安卓9patch(.9.png)图片
    block 方法参数中带有block 如何生成 如何使用
    hash_hmac
    日期(NSDate)是NSString类的格式(stringWithFormat)
    UITableView刷新单个cell或者单个Section
    iOS enum 定义与使用
    拼接url地址
    demo效果
    好东西
    关于ios7 navigationController中view的frame以及坐标点
  • 原文地址:https://www.cnblogs.com/feiblog/p/4120451.html
Copyright © 2011-2022 走看看