【发布时间】:2014-01-27 09:07:03
【问题描述】:
好的,我有一个简单的问题,我正在使用 codeigniter 框架来创建一个简单的博客。当我只设置一个控制器和一个视图时,我可以很好地将我的数据库信息(博客卷)打印到我的视图中。当我使用模型控制器视图方法时,我失败了。
这是我想在方法控制器视图设置中实现的内容。
我的原始观点有效:
<?php
//is there an array from your search form?
if($_GET){
$books = $this->db->get('blog');//query the blog table in the database
if($books->num_rows() < 1)//are there clients to show?
{
echo 'There are no blog post'; //error message if no post
}
else
{
foreach(result() as $row)//loop through the blog
{
echo $row->title."<br>";//display each titles info
}
}
}
?>
这是我为我的新模型
设置的<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog_Model extends CI_Model {
function get($args = null)
{
$query = $this->db->get('blog');
return $query->result();
foreach(result() as $row)//loop through the books
}
function insert($data)
{
$this->db->insert('blog', $data);
}
function update($data,$id)
{
$this->db->where("id",$id);
$this->db->update('blog', $data);
}
function delete($id)
{
$this->db->where("id",$id);
$this->db->delete('blog');
}
}
这是我的新控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends CI_Controller {
public function index()
{
$this->load->model('blog_model', 'blog');
$data['blogs'] = $this->blog->get();
$this->load->view('blog',$data);
}
}
我不确定要为我的新视图做什么?我只是想将博客滚动回显到视图
【问题讨论】:
标签: php codeigniter argument-passing