我得到這樣的警告缺少參數:笨,PHP構造 - 即使它存在
A PHP ERROR WAS ENCOUNTERED
Severity: Warning
Message: Missing argument 1 for User_model::__construct(), called in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\CI_PP\system\core\Loader.php on line 303 and defined
Filename: models/user_model.php
Line Number: 20
而笨,NetBeans中,PHP 5.4運行的應用程序。
這是模型/ user_model.php碼(打轉轉,忽略避免OOP的原則,請):
<?php
class User_model extends MY_Model {
public $_table = 'pp_user';
public $primary_key = 'u_id';
public $firstname;
public $lastname;
public $emailAddress;
public $password;
public $gender;
public $deliveryAddress;
public $address;
public $city;
public $zip;
public $country;
public $isAdmin;
//this is line nr.20:
public function __construct($firstname, $lastname, $emailAddress, $password, $gender, $address, $deliveryAddress, $city, $zip, $country, $isAdmin) {
parent::__construct();
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->emailAddress = $emailAddress;
$this->password = $password; //TODO!
if ($gender == 'male') {
$this->gender = 0;
} else if ($gender == 'female') {
$this->gender = 1;
} else {
$this->gender = -1;
}
$this->deliveryAddress = $deliveryAddress;
$this->address = $address;
$this->city = $city;
$this->zip = $zip;
$this->country = $country;
$this->isAdmin = $isAdmin;
}
}
我打電話和registration.php(控制器)構造函數:
$firstname = $this->input->post('tf_first_name');
$lastname = $this->input->post('tf_last_name');
$emailAddress = $this->input->post('tf_email_address');
$password = $this->input->post('tf_password_base');
$gender = $this->input->post('tf_gender');
$address = $this->input->post('tf_address');
$deliveryAddress = $this->input->post('tf_delivery_addres');
$city = $this->input->post('tf_city');
$zip = $this->input->post('tf_zip');
$country = $this->input->post('tf_country');
$isAdmin = FALSE;
$user_instance = new User_model(
$firstname,
$lastname,
$emailAddress,
$password,
$gender,
$address,
$deliveryAddress,
$city,
$zip,
$country,
$isAdmin);
如果我改變的Contor論據來自:
public function __construct($firstname, $lastname, $emailAddress, $password, $gender, $address, $deliveryAddress, $city, $zip, $country, $isAdmin)
到:
public function __construct($firstname="", $lastname="", ...) {
然後它的工作,但我不喜歡這樣的解決方案。我一直在搜索整個網絡的提示,但根據PHP OOP教程和PHP手冊,它看起來不錯。
Loader.php上線303是這樣做的:
$CI->$name = new $model();
我試圖改變的參數直接的人,當實例化對象,我試圖刪除有關父類,但問題依舊。
我真的好奇,可能是什麼問題,任何想法?
加載模型與加載庫不一樣。加載模型時,我不認爲CodeIgniter需要參數。忘掉這個 !我沒有看到你稱之爲「新的User_model」! –