我创建的codeigniter控制器类如下
I created codeigniter controller class as follows
class Poems extends CI_Controller{ function __construct() { parent::__construct(); $this->load->model('poem'); },然后在上面的类中创建方法诗如下
and then created method poem inside the above class as follows
function poem($poemID){ $data['poem']= $this->poem->get_poem($poemID); $this->load->view('poem',$data);}
/ em> * ** ** ** em> * *** / 上面我在模型get_poem()方法中创建的控制器类如下
/*******************/ for the above controller class I created in the model get_poem() method as follows
function get_poem(){ $this->db->select()->from('poems')->where(array('active'=>1,'poemID'=>$poemID))->order_by('date_added', 'desc'); $query= $this->db->get(); return $query->first_row('array'); }当我在浏览器中运行这些诗歌时, $ b当我想在浏览器中加载poem方法作为诗歌/ poem时,会出现以下错误。
When I run the poems in the browser it works fine... When I want to load the poem method as poems/poem in the browser the following error appears.
error 1: Missing argument 1 for Poems::poem() error 2: Undefined variable: poemID我可以修复此错误
推荐答案您的模型中的 get_poem()缺少参数。
Your get_poem() in your model is missing an argument.
在模型中,使用 get_poem($ poemID),就像你在控制器中。
In the model, use get_poem($poemID) like you have in the controller.
原因是你正在调用函数:
The reason being, you're calling the function:
get_poem($poemID) ^ with an argument在模型中,你使用这个:
However when you actually get to the function in the model, you use this:
get_poem() ^ without an argument这意味着,不仅 $ poemID get_poem 函数,但函数不会运行,因为它缺少参数。
This means that not only will $poemID not be a valid variable in the get_poem function, but also the function wont run because it's missing an argument.
Sidenote: poem 在写这个之后不再听起来或者看起来像一个真实的单词。
Sidenote: poem doesn't sound or look like a real word anymore after writing this.
更多推荐
Codeigniter控制器类
发布评论