Codeigniter控制器类

编程入门 行业动态 更新时间:2024-10-21 11:54:29
本文介绍了Codeigniter控制器类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建的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控制器类

本文发布于:2023-11-01 02:15:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547956.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   Codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!