codeigniter中的警告消息无效参数

时间:2015-04-16 01:43:21

标签: php codeigniter

有人请帮助我。我是codeigniter的新手。我收到了错误:

A PHP Error was encountered 
Severity: Warning  Message: Missing argument 1 for Detail_organize_cont::viewOrganize()  Filename: reader/detail_organize_cont.php  Line Number: 53 

A PHP Error was encountered 
Severity: Notice  Message: Undefined variable: id  Filename: reader/detail_organize_cont.php  Line Number: 72

我的控制器:

 function viewOrganize($id)
 {
    // Redirect unauthenticated users to signin page
    if ( ! $this->authentication->is_signed_in())
    {
        redirect('account/sign_in');
    }

    // Retrieve sign in user
    $data['account'] = $this->account_model->get_by_id($this->session->userdata('account_id'));
    // No access to users without a password
    if ( ! $data['account']->password) redirect('');


    // Enable SSL?
    $data['account'] = $this->account_model->get_by_id($this->session->userdata('account_id'));
    $data['account_details'] = $this->account_details_model->get_by_account_id($this->session->userdata('account_id'));

    $row=$this->detail_organize_model->getID($id);
    $data['organization']=$row;
    $this->load->view('reader/detail_organize_view',  $data );

我的模特:

function get_by_id($account_id)
{
    return $this->db->get_where('tb_admin', array('id' => $account_id))->row();
}


function getID($id){
    $this->db->select('id');
    $this->db->from('tb_organize');
    $this->db->where('id', $id);
    $query=$this->db->get()->result();

    return $query;
}

我的观点

  <input type="text" class="form-control" id="org" placeholder="Organization" value="<? echo $organization->id;?>" disabled>

请帮帮我。非常感谢你。

2 个答案:

答案 0 :(得分:3)

您确实需要阅读错误消息,因为这两个问题非常清楚您的问题是什么。

你的控制器中有一个方法,即

function viewOrganize($id){
  // stuff in here
}

您已将其定义为具有您必须提供的名为$ id的参数,而您正在调用它而不向其提供$ id。

这正是错误信息......

  

遇到PHP错误严重性:警告消息:丢失   Detail_organize_cont :: viewOrganize()的参数1文件名:   reader / detail_organize_cont.php行号:53

大声尖叫,大声挥动它的手臂(如果可能的话)。

答案 1 :(得分:0)

我想你是这样用uri调用这个方法的:Detail_organize_cont/viewOrganize/{ID}。您提到的错误意味着从未设置变量$id。 尝试将路由添加到application/config/route.php文件中,如下所示:

$route['Detail_organize_cont/viewOrganize/(:num)'] = 'Detail_organize_cont/viewOrganize/$1';

除此之外,您应始终将默认值设置为$id(如$id = NULL)并检查方法是否已设置参数。 CodeIgniter路由非常差并且......更好地检查您的参数;)

祝你好运!