namespace Admin\Model;
use Think\Model\ViewModel;
class NodeViewModel extends ViewModel{
//protected $tablename ="node";
public $viewFields = array(
'node'=>array('id','name','sort','status','title','icon','remark','pid','level','_type'=>'LEFT'),
'menu'=>array('id'=>'menu_id','title'=>'menu_title', '_on'=>'node.remark=menu.id'),
);
//添加菜单信息
public function addMenu(){
$date = array(
"node.name"=>$_REQUEST['name'],
"node.title"=>$_REQUEST['title'],
"node.status"=>$_REQUEST['status'],
"node.icon"=>$_REQUEST['icon'],
"node.remark"=>$_REQUEST['pid'],
"node.pid"=>0,
"node.sort"=>0,
"node.level"=>2,
);
$result = $this->add($date);
dump($date);dump($result);exit();
return $result;
}
提交的结果是这样的array (size=8)
'node.name' => string 'cccc' (length=4)
'node.ti
'node.status' => string '1' (length=1)
'node.icon' => string 'ccc' (length=3)
'node.remark' => string '2' (length=1)
'node.pid' => int 0
'node.sort' => int 0
'node.level' => int 2
boolean false
2015 08 06-11:04修改
实在是不能在视图模型添加数据了,
protected $nodeviewModel;
protected $nodeModel;
function _initialize(){
parent::_initialize();
$this->nodeviewModel = D("NodeView");
$this->nodeModel = D("Node");
}
我就又在控制器加了一个单独的node表 public function add(){
if(IS_POST){
$result = $this->nodeModel->addMenu();
dump($result);
if($result){
echo "成功";
$this->success('菜单信息添加成功');
}else{
$this->error('菜单信息添加失败!');
}
}else{
//父菜单
$pmenus = D("menu")->getPmenus();
$this->assign( array("pmenus"=>$pmenus) );
$this->display();
}
}
添加返回的是主键id数字 ,数据添加成功,echo "成功";也输出了。但是后面 $this->success('菜单信息添加成功');失败了,弹出错误,说抱歉出错了。这又是怎么回事
最佳答案
