我尝试通过此模型(page_model.php)在codeigniter中通过活动记录获取一些数据:
class Page_model extends CI_model{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_content($page){
var_dump($page);
$query = $this->db->get_where('pages', array('name' => $page));
var_dump($query);
if($query->num_rows()<1){
echo $page;
return FALSE;
}
else{
// foreach($query->result() as $row){
// $data[]=$row;
// }
// return $data;
return $data=$query->result();
}
}
}
和contents.php查看:
<div class="contents">
<?php
foreach($info as $p){
$c= $p->content;
}
echo $c;
?>
</div>
pages.php控制器:
<?php
class Pages extends CI_controller{
public function __construct(){
parent::__construct();
$this->load->model('page_model');
}
public function index($page){
echo strlen("س");
$data['info']=$this->page_model->get_content("ایران");
var_dump($data['info']);
$this->load->view('header',$data);
$this->load->view('contents',$data);
$this->load->view('footer');
}
}
它给了我这个错误:
PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/contents.php
Line Number: 3
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: c
Filename: views/contents.php
Line Number: 6
var_dump($ page):
string 'ایران' (length=10)
var_dump($ query):
object(CI_DB_mysql_result)[16]
public 'conn_id' => resource(29, mysql link persistent)
public 'result_id' => resource(32, mysql result)
public 'result_array' =>
array (size=0)
empty
public 'result_object' =>
array (size=0)
empty
public 'custom_result_object' =>
array (size=0)
empty
public 'current_row' => int 0
public 'num_rows' => int 0
public 'row_data' => null
的var_dump($信息):
boolean false
但我有一个列名为“ایران”的记录 我将permited_url_chars设置为空。
谢谢