【发布时间】:2011-11-09 03:12:25
【问题描述】:
我创建 js 文件并在单击一个 blnak 行时添加 tbar 添加按钮添加到网格中
在我写的电影控制器文件中
function ext_item($id = null) {
if(!empty($this->data)) {
if($this->Movie->save($this->data))
{
$this->set('success','true');
$this->data = array();
return;
}
else {
$this->set('success',"false");
return;
}
}
}
如何传递这个js数据?
如何在数据库中插入数据?
在控制器文件中
function create() {
$newData = json_decode($this->params['form'], true); // turn the incomin json into an array
$this->data = array(
'Movie' => array(
'date_' => $newData['date_'],
'notes' => $newData['notes'],
'asset_id' => $newData['asset_id'],
'maint_picture' => $newData['maint_picture'],
'maint_condition1' => $newData['maint_condition1'],
'maint_condition2' => $newData['maint_condition2'],
'maint_condition3' => $newData['maint_condition3'],
'maint_condition4' => $newData['maint_condition4'],
)
);
if ($this->Movie->save($this->data))
{
$data['success'] = true;
} else {
$data['success'] = false;
}
$this->set('data', $data);
//$this->layout = 'ajax';
return $this->render(null, null, '/movies/ext_item');
}
然后在js文件中
var proxy = new Ext.data.HttpProxy({
api: {
// these will map to cakephp controller actions
create: { url: 'movies_controller/create', method: 'POST' },
// read: { url: '/movies_controller/index', method: 'POST' },
//update: { url: '/movies_controller/update', method: 'POST' },
destroy: { url: 'movies_controller/destroy', method: 'POST' }
}
});
在网格中添加行
tbar: [{
text: 'Add Movie',
icon: 'images/table_add.png',
cls: 'x-btn-text-icon',
handler: function() {
grid.getStore().insert(0, new Movie({
id: 0,
notes: 'New Movie',
asset: ''
}));
rowEditor.startEditing(0, true);
}
}]
这有什么问题。它不是在数据库中插入数据。
【问题讨论】:
-
Mayur,我发布了一个答案,但很明显您不了解 Ext 和 CakePHP 的一些基础知识。您需要掌握这些基础知识,然后才能像您尝试做的那样冒险进入高级的东西。在 StackOverflow 上获得答案只是意味着你永远不会真正学习它..
标签: php json cakephp extjs integration