Error Codeigniter缺少参数

时间:2016-12-05 01:56:00

标签: php postgresql codeigniter

这是我的问题:

  

遇到PHP错误

     

严重性:警告
  消息:缺少TokoSaya :: user()的参数1,在第360行的/var/www/html/system/core/CodeIgniter.php中调用并定义了
  文件名:controllers / tokosaya.php
  行号:32

     

遇到PHP错误

     

严重程度:通知
  消息:未定义的变量:id
  文件名:controllers / tokosaya.php
  行号:34

     

发生数据库错误

     

错误号码:
  错误:“$”处或附近的语法错误第1行:SELECT * FROM usr.persons WHERE id = $ id ^
  SELECT * FROM usr.persons WHERE id = $ id
  文件名:/var/www/html/models/m_user.php
  行号:18

这是我的控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class TokoSaya extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -  
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in 
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see http://codeigniter.com/user_guide/general/urls.html
 */
function __construct()
{
    parent::__construct();
    $this->load->library('form_validation');
    $this->load->helper(array('form', 'html', 'file','string'));
    //$this->load->library('grocery_CRUD'); 
    //$this->load->model('view');
    $this->load->model('m_user');
    $this->load->model('amproker');
    //$this->data['modul'] = 'Admin';
}

function user($id)
{
    $data['user'] = $this->m_user->GetDetailUser($id);
    //$data['UserLogin'] = $this->m_user->GetUserLogin($data['user']->person)
    $data['menu'] = $this->amproker->CategoriesMenu(0,$h="");
    $data['page'] = 'user';
    $this->load->view('templates_user', $data);
}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

这是我的模特:

<?php 

/**
* 
*/
class M_User extends CI_Model
{

function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        //$this->load->library(array('My_phpmailer', 'encrypt'));
    }

function GetDetailUser($id)
{
    $query=$this->db->query("SELECT t0.*, t1.username, t1.person FROM usr.persons t0 RIGHT JOIN usr.logins t1 ON t0.id = t1.person WHERE t1.person = $id");
            return $query->row();

}

//function GetUserLogin($user)
//{
    //$query=$this->db->query("SELECT * FROM usr.logins")
    //return $query->result();
//}

}

?>

1 个答案:

答案 0 :(得分:0)

从错误的顶部开始工作......

您的方法用户($ id)期待参数,显然您没有提供参数。

所以你写这个的方式,你需要在url上提供这个参数,即localhost/tokosaya/user/1,在这种情况下,1在你的用户方法中为$ id提供1的值。

但是你需要确保这个参数确实是一个整数,并考虑如何处理一个不返回结果等的整数(id)......