我想将数据从模型传递到控制器然后查看此代码解释它。
该模型
public function get_all_college_name() {
$q = $this -> db -> query('select * from college');
if ($q -> num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
控制器代码
public function index() {
$this -> load -> model('retriver_data');
$data['rows'] = $this -> retriver_data -> get_all_college_name();
$this -> load -> view('home', $data);
//$this -> view_something('home', $data);
}
查看代码
<body>
<?php
foreach ($rows as $r) {
echo $r -> name;
}
?>
</body>
出现错误
遇到 PHP 错误
严重性:警告
消息:为 foreach() 提供的参数无效
文件名:views/home.php
行号:8