控制器可以给模型传递参数么?
同题。我看了网站上很多关于“模型”的写法的例子。也看了如何在“控制器”中调用的“模式”的方法,但是这种调用好像仅仅是调用,并没有办法传递参数。请各位达人帮忙指点一下。谢谢!o(∩_∩)o.. 传递参数?难道类的方法不能传递参数吗?function xxx(参数1, 参数2) 当然可以,看看代码:
model的片段 /**
*取得最近的几条新闻
*用法:getLastNews(5)
*/
function getLastNews($num)
{
$this->db->order_by("id", "desc");
$query = $this->db->get('news',$num,0);
if ($query->num_rows() > 0)
{
return $query;
}
}
controller的片段:
function readNews($id) {
$data["news"] = $this->News_model->getNewsById($id);
$data["lastnews"] = $this->News_model->getLastNews(5);//##############这里了###############
$data["page_title"] = $data["news"]["title"] . "(" . $data["news"]["time"] . ")";
$data["Keywords"] = $data["news"]["title"] . ",GPS车辆管理,GPS车辆管理系统,昆山GPS车辆管理系统,华领GPS车辆管理系统";
$Description = trim(strip_tags(nl2br($data["news"]["content"])));
$len = 300;
$data["Description"] = substr($Description, 0, $len);
$this->layout->view('news', $data);
}
看看controller里的“//##############这里了###############”
:) 控制器和model都是类 o(∩_∩)o...哈哈,多谢个为帮助了。解决了问题了。谢谢!
页:
[1]