我在原生PHP中看到了一个示例,它允许内联编辑或记录并更新它们。 PHP Inline Editing现在根据这段代码我有一个ajax函数,只要下面更新内容就调用更新文件是脚本:
public void SetPersistentCookies(string name, string value){
HttpCookie cookie = new HttpCookie(name);
cookie.Value = value;
cookie.Expires = DateTime.Now.AddHours(12);
Response.Cookies.Add(cookie);
}
public void GetPersistentCookies(string name)
{
//Retrive Cookie by cookies name
HttpCookie cookie = Request.Cookies[name];
Response.Write(cookie.Value);
}
模特:
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
function showEdit(editableObj) {
$(editableObj).css("background","#FFF");
}
function saveToDatabase(editableObj,column,id) {
$(editableObj).css("background","#FFF url(<?php echo site_url('img/loaderIcon.gif');?>loaderIcon.gif) no-repeat right");
$.ajax({
url: "<?php echo(site_url('Inlinedit/updateDb'));?>",
type: "POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data){
$(editableObj).css("background","#FDFDFD");
}
});
}
</script>
控制器:
public function inline( $column, $editval, $id )
{
$result = mysql_query("UPDATE users set $column = $editval WHERE id=$id");
}
类Inlinedit扩展了Admin_Controller {
<?php
}
答案 0 :(得分:2)
首先,你应该明白你不能呼叫模型功能绕过控制器。因为你需要做的是
离
在控制器中
public function just_a_method()
{
$this->Model_name->inline();/just call method
}
并在视野中
$.ajax({
url: "<?php echo base_url()?>controller/just_a_method",
答案 1 :(得分:1)
您无法直接更新模型。 创建一个用于更新代码的控制器。
<?php
class InlineEditController extends BaseController
{
public function updateDb()
{
$column = $this->input->post('column');
$editval = $this->input->post('editval');
$id = $this->input->post('id');
$this->load->model('user_m');
$this->user_m->inline( $column, $editval, $id );
return;
}
}
并在ajax中使用
<?php echo(site_url('InlineEdit/updateDb'));?>
模特必须
public function inline( $column, $editval, $id )
{
$result = mysql_query("UPDATE users set $column = $editval WHERE id=$id");
}