在TP5中发现用不了以前3.X的Create()方法,虽然用input更严谨,但是字段比较多的话还是有些不艺术的
3.X中的实现方法如下:

$Model = D('User');
$Model->create();
$Model->add();

在仔细阅读了TP5文档后,发现有这么一段:

欣喜之余便测试了一下,发现返回的内容是个类,不能直接做修改,只能接着连贯操作:

app\category\model\Category Object
(
[connection:protected] => Array
(
)
[name:protected] => Category
[table:protected] =>
[class:protected] => app\category\model\Category
[pk:protected] =>
[error:protected] =>
[validate:protected] =>
[field:protected] => Array
(
)
[visible:protected] => Array
(
)
[hidden:protected] => Array
(
)
[append:protected] => Array
(
)
[data:protected] => Array
(
[title] => dd
[sort] => 1
[pcid] => 0
)
[change:protected] => Array
(
)
[auto:protected] => Array
(
)
[insert:protected] => Array
(
)
[update:protected] => Array
(
)
[autoWriteTimestamp:protected] =>
[createTime:protected] => create_time
[updateTime:protected] => update_time
[deleteTime:protected] => delete_time
[dateFormat:protected] => Y-m-d H:i:s
[type:protected] => Array
(
)
[isUpdate:protected] =>
[updateWhere:protected] =>
[relation:protected] =>
[failException:protected] =>
)

仔细看了一下,当中有这么一段是我post的数据:

    [data:protected] => Array
(
[title] => dd
[sort] => 1
[pcid] => 0
)

  翻看了一下tp5的model类,有这么一个方法:

/**
* 获取对象原始数据 如果不存在指定字段返回false
* @access public
* @param string $name 字段名 留空获取全部
* @return mixed
* @throws InvalidArgumentException
*/
public function getData($name = null)
{
if (is_null($name)) {
return $this->data;
} elseif (array_key_exists($name, $this->data)) {
return $this->data[$name];
} else {
throw new InvalidArgumentException('property not exists:' . $this->class . '->' . $name);
}
}

调用了一下,果然可以获取到post的数组了。
实现代码如下:

$data = new Category($_POST);
$data = $data->getData();

分享一个TP5实现Create()方法的心得的更多相关文章

  1. 分享一个 jquery serializeArray()序列化方法

    http://www.365mini.com/page/jquery-serializearray.htm http://www.365mini.com/diy.php?f=jquery-serial ...

  2. 怎么将DWG转PDF?分享一个在线转换方法

    了解CAD的朋友们都知道,在使用CAD制图软件绘制图纸的时候,默认的CAD图纸保存格式就是为DWG格式.但是DWG格式的文件不能够直接进行打开查看,就需要将DWG转PDF格式.那具体要怎么来进行操作呢 ...

  3. 分享一个解决MySQL写入中文乱码的方法

    分享一个解决MySQL写入中文乱码的方法 之前有发帖请教过如何解决MySQL写入中文乱码的问题.但没人会,或者是会的人不想回答.搜索网上的答案并尝试很多次无效,所以当时就因为这个乱码问题搁浅了一个软件 ...

  4. 分享一个解析XML成为php数组的方法

    原文:分享一个解析XML成为php数组的方法 <?php /* * To change this template, choose Tools | Templates * and open th ...

  5. 分享一个.NET(C#)按指定字母个数截断英文字符串的方法–提供枚举选项,可保留完整单词

    分享一个.NET(C#)按字母个数截断英文字符串的方法,该方法提供枚举选项.枚举选项包括:可保留完整单词,允许最后一个单词超过最大长度限制,字符串最后跟省略号以及不采取任何操作等,具体示例实现代码如下 ...

  6. 分享一个 Java String split 快速分割的方法

    java中string.split() 方法比较强大,但是split()方法采用正则表达式,速度相对会慢一点, 其实大多数场景下并不需要使用正则表达式,下面分享一个不使用正则表达式分隔字符串的方法. ...

  7. 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  8. (转)分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)

    分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...

  9. 分享一个SQLSERVER脚本

    原文:分享一个SQLSERVER脚本 分享一个SQLSERVER脚本 很多时候我们都需要计算数据库中各个表的数据量很每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tablespac ...

随机推荐

  1. PCL中point cloud的数据类型

    出处: http://wiki.ros.org/pcl/Overview 1.数据类型 1.1 ROS中point cloud数据类型 sensor mesgs::PointCloud sensor ...

  2. SVN 文件解锁

    之前一直一个人用svn,后来团队扩编,同事使用svn下载项目后.我却无法提交了,出现以下错误: locked in another working copy No lock on path (Stat ...

  3. Linux Kernel Version Numbering

    Because there are numerous revisions and releases of the Linux kernel and new ones are developed at ...

  4. Android Studio 总结

    1:添加插件 File->Setting->plugins->Browse repoistories

  5. uva674 Coin Change ——完全背包

    link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. andriod学习之一

    今天安装了Android Studio, 但PinyinIME没有导入成功.然后看了Android的一些基础. 知道了Android的基本组件: Activity,服务,内容提供程序,广播接收器. 大 ...

  7. Oracle建表添加数据

  8. mysql保存数据提示1366 Incorrect string value: ‘\xF0\x9F\x98\x8A\xF0\x9F…’ 解决

    在保存数据时我们如果页面编辑与数据库字段编码不一样或字符集超出你了mysql数据库中的字符类型就有可能出一\\xF0\\x9F\\x98\\x8A\\xF0\\x9F提示了,下面我来简单的解决方法. ...

  9. CSS + DIV 让页脚始终保持在页面底部

    来源:David's Blog     http://www.DavidQiu.com/ 文章链接:http://blog.davidqiu.com/post/2013-06-17/400517539 ...

  10. SSIS 项目部署模型

    微软 BI 系列随笔 - SSIS 2012 基础 - SSIS 项目部署模型 关于部署 SSIS 2012 支持两种部署模型:项目部署模型和包部署模型. 使用项目部署模型可以将项目部署到 Integ ...