ThinkPHP基础操作《一》

1   http://localhost/ThinkPHP5.0/public
    等价于设置域名
/index.php/index/user/index
入口文件   前台  控制器  方法


2    ./ 当前目录
     ../上一级目录




3   跨控制器调用
#实例化当前模块User控制器
controller('User';)
#实例化后台模块控制器
controller('Admin\User');


4  跨方法调用
#实例化当前控制器test方法
action('test');
实例化当前模块User控制器test方法
action('User\test');
实例化Admin模块User控制器test方法
action('Admin\User\test');


5  加载顺序
(1) 优先级
 动态配置>模块配置>场景配置>扩展配置>应用配置>惯例配置
(2)加载顺序
惯例配置->应用配置->扩展配置->场景配置->模块配置->动态配置


6 获取类
(1)Config类
  Config::get();
(2)config方法

  config();


 7 定义路由规格
Route::rule('/','index/index/index');
Route::rule('test','index/index/test')

引入系统类


8 页面跳转信息
引入系统下Controller类
$this->success(提示信息,跳转地址,用户自定义数据,,header信息);

$this->error();


9 重定向

$this->redirect();


10  空控制器和空操作


11使用命令行  
(1)创建资源控制器
php think make:controller app\index\controller\Goods
(2)创建数据模型
php think make:mode app\index\model\Goods
(3)清空runtime 临时文件

php think clear


12 加载页面
(1)return view();
(2)使用系统View类
       use think\View;
       $A = new View();
       return $A->fetch();
(3)通过Controller类,需要控制器继承系统类
     use think\Controller;
     class A extends Controller{
    public function index(){
     return $this->fetch();
}

}


13连接数据库
(1)$DB = new Db;
  $data =$DB::query('select * from tp_user'); 
(2)$DB  =DB::connect([
'type'         => 'mysql',
'hostname => 'localhost',
'database' => 'thinkphp',
'username'=>'root',
'password =>'',
'hostport' =>'3306'
]);
$result = $DB->query('');

$result = $Db->table('tp_user')->select();

(3)$Db = Db::connect("mysql://root:[email protected]:3306/thinkphp#utf8");


14 助手函数db('user')->select();
但每次默认重新连接数据库
15 $data = DB::table('sgs_adminstor')->where('id','>',10)->where('id','<','15')->select();
16 page分页函数
$data = Db::table('user')->page('1,5')->select();
17多表查询
select goods.*,type.name tname from type,goods where goods.cid = type.id

猜你喜欢

转载自blog.csdn.net/liuanpingfirst/article/details/80724872
今日推荐