这是我在此控制器中的 home.php 文件我面临致命错误:Uncaught ArgumentCountError: 我还附了一个截图,在这个截图错误中提到,你可以通过这个截图轻松理解错误,我是CodeIgniter的新手。 [ 我只上传我的控制器相关文件。
<?php
class home extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('select');
$this->load->helper(array('form', 'url', 'html'));
$this->load->library(array('form_validation', 'session'));
}
function records() {
$ytl['dta'] = $this->users->datas();
//$this->load->view('info',$ytl);
//echo "<pre>controller";print_r($ytl);
}
function primezone() {
$ytl['dta'] = $this->users->datas();
echo "<pre>controller";
print_r($ytl);
}
function form($id) {
//die($id);
if ($this->input->post()) {
//echo"<pre>";print_r( $this->input->post());die;
$this->form_validation->set_rules('fname', 'First Name', 'required|min_length[5]');
$this->form_validation->set_rules('lname', 'Last Name', 'required|callback_check_picture[lname]');
//$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('mobile', 'Mobile Number', 'required|callback_valid_phone_number[mobile]');
$this->form_validation->set_error_delimiters('<h1 class="error">', '</h1>');
if ($this->form_validation->run() == TRUE) {
$data = [
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'mobile' => $this->input->post('mobile'),
'message' => $this->input->post('message'),
];
if (empty($id)) {
$ytl = $this->select->insertdata($data);
} else {
$ytl = $this->select->updatedata($data, $id);
}
if ($ytl) {
$this->session->set_flashdata('message', 'Successfully Added.');
redirect('home');
}
} else {
//$this->load->view('form');
}
}
$ytl['dta'] = $this->select->getDataById($id);
//echo "<pre>";print_r($ytl);die;
$this->load->view('form', $ytl);
}
public function check_picture($a) {
if ( ! is_numeric($a)) {
return TRUE;
} else {
$this->form_validation->set_message('check_picture', 'Please enter only char value');
return FALSE;
}
}
function valid_phone_number($value) {
$value = strlen($value);
//echo $value;die;
if ($value == 10) {
return TRUE;
} else {
$this->form_validation->set_message('valid_phone_number', 'Mobile number not in range'); //{10}
return FALSE;
}
}
public function index() {
//load the database
//$this->load->database();
//load the model
$this->load->model('select');
//load the method of model
$data['h'] = $this->select->select();
//return the data in view
$this->load->view('fetch_view', $data);
}
public function delete() {
$this->load->model('select');
$id = $this->input->get('id');
if ($this->select->deleteuser($id)) {
$data['data'] = $this->select->getuser();
$this->load->view('fetch_view', $data);
}
}
}
答案 0 :(得分:0)
在控制器功能中设置默认id值,如
function form($id = null){
....
}
答案 1 :(得分:0)
您提到的错误通常是在param
提及function
和传递的错误时出现的错误。
根据你的代码
public function form($id)
$id
是必需的,你没有通过它。
所以将代码更改为
public function form($id=null)