douyunhuan9886 2016-11-13 10:10
浏览 55
已采纳

CodeIgniter中未定义的变量ID

I have this todo list project.

My model

class Model_lists extends CI_Model {

function Model_list(){
    parent::__construct();
}

function list_get($id){
    $this->load->database();
    $query = $this->db->get_where('lists', array('id'=>$id));
    return $query->row_array();
}

My Controller

public function view_list($id){
    $this->load->model('model_lists');
    $data["query"] = $this->model_lists->list_get($id);
    $this->load->view('lists/view_list',$data);
}

List view

<?php
 echo $query['list_by'];
?>

However, when I access the view I get 2 PHP errors

1) Message: Missing argument 1 for Lists::view_list()
2) Message: Undefined variable: id

This is how I call the list:

<a class="view_list" href="<?php echo site_url("lists/view_list?lid={$row->list_id}");?>"><i class="icon-eye"> </i></a>
  • 写回答

1条回答 默认 最新

  • dongti8535 2016-11-13 14:24
    关注

    Your site url is not correct. The error is because no id is being passed and in CI (unless you have set to use query arrays) then the url is of the format www.example.com/controller/method/argument

    So try:

    href="<?php echo site_url('lists/view_list/'.$row->list_id); ?>"
    

    In the docs: http://www.codeigniter.com/user_guide/helpers/url_helper.html#site_url

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改