作业1:多例模式访问
实例
<?php namespace app\admin\controller; use app\BaseController; class Index extends BaseController { public function index() { echo 'hello worl22222d'; // return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V6<br/><span style="font-size:30px">13载初心不改 - 你***的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq***/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink***/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>'; } public function a() { echo '我是杨发国'; } public function hello($name = 'ThinkPHP6') { return 'hello,' . $name; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例
作业2:数据库增删改查
实例
<?php namespace app\admin\controller; use app\BaseController; use think\facade\Config; use think\facade\Db; class Index extends BaseController { public function index() { //原生写法 // $query = Db::query("select * from user where uid=2"); // print_r($query); // $select = Db::table('user')->where('status',1)->select(); // print_r($select); // $find = Db::table('user')->where('uid',1)->find(); // print_r($find); // $data = ['phone'=>'13355555555','u_name'=>'穆念慈','sex'=>2]; // $insert = Db::table('user')->insert($data); // print_r($insert); // $data = ['phone'=>'13422222222','u_name'=>'一灯大师']; // $update = Db::table('user')->where('uid',2)->update($data); // print_r($update); $delete = Db::table('user')->where('uid',1)->delete(); print_r($delete); } public function execute() { // $execute = Db::execute("insert into user set `phone`='13211111111',`u_name`='一灯大师' "); // print_r($execute); // $execute = Db::execute("update user set `u_name`='杨发国' where `uid`=4 "); // print_r($execute); } }
运行实例 »
点击 "运行实例" 按钮查看在线实例