欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

怎么访问模型对象里面的属性

  1. $model = D('wallpapers');
  2.  dump($model);
复制代码
 
复制代码
 
  1. object(Model)#9 (20) {
  2.   ["_extModel":"Model":private] => NULL
  3.   ["db":protected] => object(DbMysqli)#5 (18) {
  4.     ["dbType":protected] => string(6) "MYSQLI"
  5.     ["autoFree":protected] => bool(false)
  6.     ["model":protected] => string(7) "_think_"
  7.     ["pconnect":protected] => bool(false)
  8.     ["queryStr":protected] => string(30) "SHOW COLUMNS FROM `wallpapers`"
  9.     ["modelSql":protected] => array(2) {
  10.       ["admin"] => string(130) "SELECT COUNT(id) AS tp_count FROM `admin` WHERE ( `name` = 'shine' ) AND ( `pass` = '202cb962ac59075b964b07152d234b70' ) LIMIT 1  "
  11.       ["wallpapers"] => string(30) "SHOW COLUMNS FROM `wallpapers`"
  12.     }
  13.     ["lastInsID":protected] => NULL
  14.     ["numRows":protected] => int(12)
  15.     ["numCols":protected] => int(6)
  16.     ["transTimes":protected] => int(0)
  17.     ["error":protected] => string(0) ""
  18.     ["linkID":protected] => array(1) {
  19.       [0] => object(mysqli)#4 (18) {
  20.         ["affected_rows"] => int(12)
  21.         ["client_info"] => string(6) "5.5.20"
  22.         ["client_version"] => int(50520)
  23.         ["connect_errno"] => int(0)
  24.         ["connect_error"] => NULL
  25.         ["errno"] => int(0)
  26.         ["error"] => string(0) ""
  27.         ["field_count"] => int(6)
  28.         ["host_info"] => string(25) "Localhost via UNIX socket"
  29.         ["info"] => NULL
  30.         ["insert_id"] => int(0)
  31.         ["server_info"] => string(10) "5.5.23-cll"
  32.         ["server_version"] => int(50523)
  33.         ["stat"] => string(150) "Uptime: 1319442  Threads: 2  Questions: 155064146  Slow queries: 411  Opens: 709669  Flush tables: 1  Open tables: 64  Queries per second avg: 117.522"
  34.         ["sqlstate"] => string(5) "00000"
  35.         ["protocol_version"] => int(10)
  36.         ["thread_id"] => int(11976305)
  37.         ["warning_count"] => int(0)
  38.       }
  39.     }
  40.     ["_linkID":protected] => object(mysqli)#4 (18) {
  41.       ["affected_rows"] => int(-1)
  42.       ["client_info"] => string(6) "5.5.20"
  43.       ["client_version"] => int(50520)
  44.       ["connect_errno"] => int(0)
  45.       ["connect_error"] => NULL
  46.       ["errno"] => int(0)
  47.       ["error"] => string(0) ""
  48.       ["field_count"] => int(6)
  49.       ["host_info"] => string(25) "Localhost via UNIX socket"
  50.       ["info"] => NULL
  51.       ["insert_id"] => int(0)
  52.       ["server_info"] => string(10) "5.5.23-cll"
  53.       ["server_version"] => int(50523)
  54.       ["stat"] => string(150) "Uptime: 1319442  Threads: 2  Questions: 155064146  Slow queries: 411  Opens: 709669  Flush tables: 1  Open tables: 64  Queries per second avg: 117.522"
  55.       ["sqlstate"] => string(5) "00000"
  56.       ["protocol_version"] => int(10)
  57.       ["thread_id"] => int(11976305)
  58.       ["warning_count"] => int(0)
  59.     }
  60.     ["queryID":protected] => object(mysqli_result)#6 (5) {
  61.       ["current_field"] => int(0)
  62.       ["field_count"] => int(6)
  63.       ["lengths"] => NULL
  64.       ["num_rows"] => int(12)
  65.       ["type"] => int(0)
  66.     }
  67.     ["connected":protected] => bool(true)
  68.     ["comparison":protected] => array(10) {
  69.       ["eq"] => string(1) "="
  70.       ["neq"] => string(2) "<>"
  71.       ["gt"] => string(1) ">"
  72.       ["egt"] => string(2) ">="
  73.       ["lt"] => string(1) "<"
  74.       ["elt"] => string(2) "<="
  75.       ["notlike"] => string(8) "NOT LIKE"
  76.       ["like"] => string(4) "LIKE"
  77.       ["in"] => string(2) "IN"
  78.       ["notin"] => string(6) "NOT IN"
  79.     }
  80.     ["selectSql":protected] => string(96) "SELECT%DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%%LIMIT% %UNION%%COMMENT%"
  81.     ["bind":protected] => array(0) {
  82.     }
  83.   }
  84.   ["pk":protected] => string(2) "id"
  85.   ["tablePrefix":protected] => string(0) ""
  86.   ["name":protected] => string(10) "wallpapers"
  87.   ["dbName":protected] => string(0) ""
  88.   ["connection":protected] => string(0) ""
  89.   ["tableName":protected] => string(0) ""
  90.   ["trueTableName":protected] => string(10) "wallpapers"
  91.   ["error":protected] => string(0) ""
  92.   ["fields":protected] => array(15) {
  93.     [0] => string(2) "id"
  94.     [1] => string(6) "device"
  95.     [2] => string(4) "type"
  96.     [3] => string(8) "thumburl"
  97.     [4] => string(6) "picurl"
  98.     [5] => string(7) "pic_url"
  99.     [6] => string(7) "content"
  100.     [7] => string(8) "dateline"
  101.     [8] => string(8) "lastdigg"
  102.     [9] => string(5) "diggs"
  103.     [10] => string(7) "reviews"
  104.     [11] => string(4) "flag"
  105.     ["_autoinc"] => bool(true)
  106.     ["_pk"] => string(2) "id"
  107.     ["_type"] => array(12) {
  108.       ["id"] => string(7) "int(11)"
  109.       ["device"] => string(29) "enum('iPhone','iPad','ipad3')"
  110.       ["type"] => string(11) "varchar(60)"
  111.       ["thumburl"] => string(12) "varchar(255)"
  112.       ["picurl"] => string(12) "varchar(255)"
  113.       ["pic_url"] => string(12) "varchar(255)"
  114.       ["content"] => string(4) "text"
  115.       ["dateline"] => string(7) "int(11)"
  116.       ["lastdigg"] => string(7) "int(11)"
  117.       ["diggs"] => string(7) "int(11)"
  118.       ["reviews"] => string(7) "int(11)"
  119.       ["flag"] => string(22) "enum('pending','open')"
  120.     }
  121.   }
  122.   ["data":protected] => array(0) {
  123.   }
  124.   ["options":protected] => array(0) {
  125.   }
  126.   ["_validate":protected] => array(0) {
  127.   }
  128.   ["_auto":protected] => array(0) {
  129.   }
  130.   ["_map":protected] => array(0) {
  131.   }
  132.   ["_scope":protected] => array(0) {
  133.   }
  134.   ["autoCheckFields":protected] => bool(true)
  135.   ["patchValidate":protected] => bool(false)
  136.   ["methods":protected] => array(13) {
  137.     [0] => string(5) "table"
  138.     [1] => string(5) "order"
  139.     [2] => string(5) "alias"
  140.     [3] => string(6) "having"
  141.     [4] => string(5) "group"
  142.     [5] => string(4) "lock"
  143.     [6] => string(8) "distinct"
  144.     [7] => string(4) "auto"
  145.     [8] => string(6) "filter"
  146.     [9] => string(8) "validate"
  147.     [10] => string(6) "result"
  148.     [11] => string(4) "bind"
  149.     [12] => string(5) "token"
  150.   }
  151.  }
复制代码
 
复制代码
 
dump($model->pk);
dump($model->fields);

都是 NULL
最佳答案
 
979137 2013年12月04日
恍然大悟! 哈哈~~~
评论(2相关
9791372013年12月04日
恍然大悟! 哈哈~~~
回复hunduncn2013年12月04日
pk是protected,当然取不到了。
haran2013年12月04日
  1.  
  2.     echo '<pre>';
  3.     print_r($model);
  4.  
复制代码
复制代码
复制代码
 

就看清楚啦。
回复9791372013年12月04日
不是看不看清楚的问题。
已经知道啥原因了,
来自  http://www.thinkphp.cn/topic/9118.html
普通分类: