首页 技术 正文
技术 2022年11月17日
0 收藏 986 点赞 3,674 浏览 1192 个字

common/function.php 看里面函数大全,啥玩意都有

Tpl中的是模板文件,action中是控制类,Model中有action用到的一些东西,例:

class IndexAction extends Action{
public function index(){
$Model = D('Form');
$this->assign('list3',$Model->getList());
$this->display();
} public function read($id=0){
$Model = D('Form');
$this->assign('vo',$Model->getDetail($id));
$this->display();
}
}

FormModel.class.php

<?php
class FormModel extends Model {
public function getList($count=){
return $this->order('id DESC')->field(true)->limit($count)->select();
} public function getDetail($id=){
return $this->field(true)->find($id);
}
}

最后生成缓存文件在Runtime/cache目录中

模板html中一行:{:U(‘test’)}  生成的代码为<?php echo U(‘test’);?>最后显示在浏览器上为:/Examples/group/Index/test

U(”)类似相对目录路径+test

现在有个问题就是/Examples/group/Index/read/id/1这样的目录自己打不开不知道不是apache设置问题2013-09-25 22:00明天在弄

ThinkPHP 中M方法和D方法的具体区别

ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类。

使用M方法

如果是如下情况,请考虑使用 M方法:

  1. 对数据表进行简单的 CURD 操作而无复杂的业务逻辑时
  2. 只有个别的表有较为复杂的业务逻辑时,将 M方法 与实例化 CommonModel 类进行结合使用

M方法 甚至可以简单看着就是对参数表名对应的数据表的操作:

$User = M('User'); 

使用D方法

如果是如下情况,请考虑使用 D方法:

  1. 需要使用 ThinkPHP 模型中一些高级功能如自动验证功能(create()方法中实现)、关联模型等
  2. 业务逻辑比较复杂,且涉及的表众多
  3. 将业务逻辑定义在了自定义的模型类里面(Lib/Model目录下),而想在操作中实现这些业务逻辑

另外 D方法 不支持跨项目调用,需要使用:

$User = D('User', 'Admin');    // 实例化 Admin 项目下面的 User 模型 $User = D('Admin.User');        // 启用了项目分组 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292