我是Codeigniter的新手,请帮助我。
我的Codeigniter网址是 - http://localhost/framework/CodeIgniter/index.php/restaurant/patna/
我想获取所有数据。
我设置路线 -
$route['restaurant(:any)'] = "Restaurant/getRestaurantByCity/$1";
我在Controller中的功能是
这里我想要在下面的函数中传递cat_id的类别id来获取该类别的所有数据
public function getRestaurantByCity()
{
$rst_list = $this->Restaurant_model->get_restaurant_by_city();
}
答案 0 :(得分:0)
试试这个
<强>控制器强>
$this->data['RestaurantByCity'] = $this->Restaurant_model->getRestaurantByCity();
echo "<pre>"; print_R($this->data['RestaurantByCity']);
<强>模型强>
public function getRestaurantByCity($ids){
$sql ="select * from categoriestableName where categories_id in($ids) order by categories_id asc";
$rs = $this->db->query($sql);
foreach($rs->result() as $record ){
$result[] = $record;
}
return $result;
}
答案 1 :(得分:0)
这应该有效
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Restaurant extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function getRestaurantByCity($id)
{
$this->load->model('Restaurant_model');
$rst_list = $this->Restaurant_model->get_restaurant_by_city($id);
}
}