繁体   English   中英

删除记录后重定向上一页

[英]Redirecting the previous page after deleting a record

我是CI的新手。 我希望您能为我解决问题。 :)我试图重定向站点的上一页,该页面的表包含数据库中的数据。 我不断收到消息

Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\..... 
Call to a member function result() on a non-object in C:\xampp\htdocs\findiningcebu.com\application\views\admin\SearchRestoDisplay.php on line 122

和那条说的通知

Undefined variable: restaurantinfo....Backtrace:    
File: C:\xampp\htdocs\findiningcebu.com\application\views\admin\SearchRestoDisplay.php
Line: 122

这是我的代码:

视图:

<div class = "list">
<table border=2>
<tr style="font-size: 16px; background-color: rgba(26, 26, 38, 0.5);">
<th>Name</th>
<th>Logo</th>
<th>Cuisine</th>
<th>Action</th>
</tr>

    <?php
      $restoname= ''; 
      $restologo= '';
      $cuisine= '';

      foreach($restaurantinfo->result() as $row) 
      { 
        $restoname= $row->restoname; 
        $restologo= $row->restologo;
        $cuisine= $row->cuisine;
       ?>

控制器:

public function delete($id)
{
    $this->load->model('AdminModel');
    $delete = $this->AdminModel->delete($id);
    $this->load->view('admin/SearchRestoDisplay');
}

 public function searchresto()
{
    $restoinfo = $_POST['restoinfo'];
    $searchinfo = $_POST['searchinfo'];

    $this->load->model('AdminModel');
    $restaurantinfo['restoinfo'] = $restoinfo;
    $restaurantinfo['searchinfo'] = $searchinfo;
    $restaurantinfo['restaurantinfo']=$this->AdminModel->searchrestaurant($restoinfo,$searchinfo);
    $this->load->view('admin/SearchRestoDisplay',$restaurantinfo);
}

模型:

public function delete($id){
$this->db->delete('restaurants',array('id'=>$id));
}

发生这种情况是因为result()是数据库类的方法,并且您试图在$restaurantinfo上使用此方法,并且它看起来像一个简单的数组。

我建议您$this->AdminModel->searchrestaurant返回类似这样的内容

 function searchrestaurant(){
   /*stuff*/
   return $query->result_array(); 
}

这样,您可以简单地在您的视图上进行讲授

foreach($restaurantinfo as $row) 
      { 
        $restoname= $row['restoname']; 
        $restologo= $row['restologo'];
        $cuisine= $row['cuisine'];
      }

该问题看起来像您正在尝试在视图上使用数据库类的方法(其中查询不存在)。

因此,更改searchrestaurant函数,或在视图上执行查询..我不推荐这样做。

希望能有所帮助

加载视图时,在删除功能中,未传递值'$ restauranrinfo',这就是视图中餐厅详细信息丢失的原因。 在加载视图并在视图中传递值之前,从数据库中获取餐厅的详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM