我在我的应用程序中使用 Codeigniter,我是新手。我从 Codeigniter 收到几个错误。我因变量错误而分心。
所以,这是我的模型:
class menuObjek extends CI_Model{
public function __construct(){
parent::__construct();
$this->load->database();
}
public function getWisata($perPage,$uri){
$this->db->select("namaObjWisata, deskripsiObjWisata");
$this->db->from("objekwisata");
$this->db->order_by("kategori","ASC");
$getData = $this->db->get("", $perPage, $uri);
if($getData->num_rows() > 0){
return $getData->result_array();
}else{
return null;
};
}
}
控制器:
class showObjek extends CI_Controller {
private $data= array();
public function showObjek(){
parent:: __construct();
$this->load->model("menuobjek","", TRUE);
$this->load->helper("url");
$this->load->database();
$this->load->library("pagination");
}
public function iniShow() {
$this->db->select("*");
$this->db->from("objekwisata");
$getData = $this->db->get();
$result = $getData->num_rows();
//var $detail;
$config["base_url"] = base_url()."index.php/showObjek/iniShow/";
$config["total_rows"] = $result;
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$config["full_tag_open"] = "<p>";
$config["full_tag_close"] = "</p>";
$config["first_link"] = "<< First";
$config["last_link"] = "Last >> ";
$data["detail"] = $this->menuobjek->getWisata($config["per_page"], $this->uri->segment(3));
$this->pagination->initialize($config);
$data["pagination"]= $this->pagination->create_links();
$this->load->view("menu_view", $data);
}
}
最后是视图:
//if(isset($detail)){
foreach($detail as $rows){
echo"
<li>
<a href=''>
<img src='#' class='img-rounded' />
<p class='judul_objek'>".$rows['namaObjWisata']."</p>
<article>
".$rows['deskripsiObjWisata']."
</article>
</a>
</li>
";
}
//}
这显示了这些错误:
遇到 PHP 错误
严重性:通知
消息:未定义的变量:详细信息
文件名:views/menu_view.php
行号:124
遇到 PHP 错误
严重性:警告
消息:为 foreach() 提供的参数无效
文件名:views/menu_view.php
行号:124
我真的很困惑。我必须解决这个问题。请任何人帮助我。
谢谢你。