简单普及一下MVC [模型层M,控制层C,视图层V]
视图
视图是用户看到并与之交互的界面。
模型
模型表示企业数据和业务规则。
控制器
控制器接受用户的输入并调用模型和视图去完成用户的需求
第一个小修改
Application\Home\Controller (Controller 字面理解我们也知道这个是控制层 MVC 的C)
IndexController.class.php
修改$this->show();里的内容
还是这个文件
public function hello(){
echo ‘hello,thinkphp!’;
}
访问
http://localhost/thinkphp/Home/Index/hello
就出现了hello….
后置策略,就是在文件输出以后,继续执行。
前置对应的就是_before_hello()
public function _after_hello(){
echo 'after
';
}
hello,thinkphp!after
新建业务模块
/thinkphp/目录下直接建立一个文件叫admin.php
// 检测PHP环境
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
define('THINK_PATH','./ThinkPHP/');
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG',True);
// 定义应用目录
define('APP_PATH','./admin/');
define('APP_NAME','admin');
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
// 亲^_^ 后面不需要任何代码了 就是如此简单
程序将自动创建admin文件夹,并存放所有需要的文件目录
进入admin的控制模块找到文件 IndexController.class.php
admin\Home\Controller
$this->show('
欢迎使用 ThinkPHP!
$this->display();
\thinkphp\admin\Home\View\Index (View 视图层)
这里目录下 搞一个index.html
随便写点
就好了。
模板赋值
IndexController.class.php里
$this->assign(‘name’,'月小升’);
$this->display();
\thinkphp\admin\Home\View\Index\index.html
我是:{$name}
就能显示了。
学一点数据库的配置
thinkphp\Application\Home\Conf
下的文件config.php
return array(
//'配置项'=>'配置值'
// 添加数据库配置信息
'DB_TYPE' => 'mysql', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'thinkphp', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => '', // 密码
'DB_PORT' => 3306, // 端口
'DB_PREFIX' => 'think_', // 数据库表前缀
);
public function hello(){
echo 'hello,thinkphp!';
}
改成
public function hello(){
echo 'hello,thinkphp!';
$Data = M('User'); // 实例化Data数据模型
$this->data = $Data->select();
//$this->display();
print_r($this->data);
}
数据库建立一个表think_user
执行http://localhost/thinkphp/Home/Index/hello
hello,thinkphp!Array ( [0] => Array ( [id] => 1 [name] => ghj [pwd] => 123456 ) ) after
读取原生SQL
echo M("User")->getLastSql();
执行原生SQL
使用原生SQL很简单,我们甚至不需要实例化任何的模型,例如:
$Model = new Model(); // 实例化一个空模型
下面的方法是等效的
$Model = D(); 或者 $Model = M();
// 下面执行原生SQL操作
$Model->query('select * from think_user where status=1');
$Model->execute('update think_user set status=1 where id=1');
如果你实例化了某个模型,仍然可以执行原生SQL操作,不受影响,例如:
$User = D('User');
$User->query('select * from think_user where status=1');
$User->execute('update think_user set status=1 where id=1');
荒野乱斗国际版 (BrawlStars)最新版本v56.274
下载一波超人内置修改器菜单版 安卓版v1.0.2
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载继承了一座戏园子无限声望铜钱版 内置菜单最新版v1.7
继承了一座戏园子折相思版是游戏的破解版本,在该版本中为玩家提
山河半世橙光清软金手指版 无限鲜花v3.24
山河半世是一款超级好玩的橙光恋爱游戏,在游戏中玩家们需要扮演
蓬莱手游折相思版 安卓版v1.0.0
蓬莱免广告版是游戏的修改版本,在该版本中为玩家去除了广告,玩
当红影后橙光游戏破解版2025 最新版v1.0
当红影后橙光破解版是一款超级好玩的娱乐圈题材的橙光游戏,在这
忽然成了万人迷清软完结版 无限鲜花版v12.15
忽然成了万人迷破解版是一款非常好玩的男性向橙光游戏,在有一天