thinkphp 3.2 視圖模型 查詢 出來bool(false) 求解
模型裡這麼寫的
namespace Home\Model;
use Think\Model\ViewModel;
class PicViewModel extends ViewModel{
public $viewFields =array(
'picture'=> array('picTitle','picToken','picCategroy','picAuthor','picPostTime','_type'=>'LEFT'),
'picture_attachment' =>array('pictureid','pictureurl','creattime','_on'=>'picture.picToken = picture_attachment.pictureid'),
);
}
picture和picture_attachment兩張表
控制器裡這麼寫的 我用D方法執行個體化PicView 這個是必須在資料庫裡真實的表名麼
public function Pic(){
$PicModel =D('PicView');
dump($PicModel);
$s = $PicModel->select();
dump($s);
}
返回的一些錯誤
["db":protected] => object(Think\Db\Driver\Mysql)#8 (19) {
["dbType":protected] => NULL
["autoFree":protected] => bool(false)
["model":protected] => string(7) "_think_"
["pconnect":protected] => bool(false)
["queryStr":protected] => string(0) ""
["modelSql":protected] => array(0) {
}
["lastInsID":protected] => NULL
["numRows":protected] => int(0)
["numCols":protected] => int(0)
["transTimes":protected] => int(0)
["error":protected] => string(0) ""
["linkID":protected] => array(0) {
}
["_linkID":protected] => NULL
["queryID":protected] => NULL
["connected":protected] => bool(false)
["autoinc":protected] => bool(false)
["patchValidate":protected] => bool(false)
------解決思路----------------------
# PicView 模型初始化,如果該PicView類存在則調用並初始化,如果不存在 ,則根據表名初始化模型
$PicModel =D('PicView');
#輸出所有資料 實際執行的SQL語句是
# SELECT * FROM PicView
$s = $PicModel->select();
PHP初學者不建議直接看架構!