Php 代码点火器:ArgumentErrorCount
我正在尝试为用户创建编辑配置文件功能。当用户提交表单时,它会更新数据库中的数据。但当我尝试访问“编辑配置文件”页面时,会出现以下错误: 类型:ArgumentCountError 消息:函数Profile::editProfile的参数太少,在第532行的/Applications/MAMP/htdocs/Capstone/system/core/CodeIgniter.php中传递了0,预期正好是1 我在函数中传递$id,所以我不确定为什么会发生这种情况 型号:Php 代码点火器:ArgumentErrorCount,php,codeigniter,Php,Codeigniter,我正在尝试为用户创建编辑配置文件功能。当用户提交表单时,它会更新数据库中的数据。但当我尝试访问“编辑配置文件”页面时,会出现以下错误: 类型:ArgumentCountError 消息:函数Profile::editProfile的参数太少,在第532行的/Applications/MAMP/htdocs/Capstone/system/core/CodeIgniter.php中传递了0,预期正好是1 我在函数中传递$id,所以我不确定为什么会发生这种情况 型号: public function
public function updateUser($id)
{
$data = array(
'age' => $this->input->post('age'),
'location' => $this->input->post('location'),
'favouritebeer' => $this->input->post('favouritebeer'),
'website' => $this->input->post('website'),
'bio' => $this->input->post('bio')
);
$this->db->where('id', $id);
$this->db->update('users', $data);
return $id;
}
public function getUser($id)
{
$this->db->select('*');
$this->db->where('id', $id);
$this->db->from('users');
$query = $this->db->get();
return $query-row();
}
控制器:
public function editProfile($id)
{
$this->load->model('user_model');
$this->load->view('templates/header');
$this->load->view('pages/editprofile');
$this->load->view('templates/footer');
if(isset($_POST['updatechanges'])) {
if($this->user_model->getUser($id)) {
$this->session->set_flashdata('success', 'Profile updated!');
redirect('profile', 'refresh');
}
}
}
视图:
<div class ="container">
<?php
$con=mysqli_connect("localhost","root","admin","Mydb");
$sql = mysqli_query($con, "SELECT id, username, age, location, favouritebeer, website, bio FROM users WHERE username = '" . $_SESSION['username'] . "'");
$row = mysqli_fetch_array($sql);
?>
<h2><?php echo $_SESSION['username'];?>'s Profile</h2>
<a href="<?php echo base_url(); ?>index.php/Auth/logout" style="color:darkblue">Logout</a>
</br>
<a href="<?php echo base_url(); ?>index.php/Auth/logout" style="color:darkblue">Change password</a>
</br>
<a href="<?php echo base_url(); ?>index.php/Auth/logout" style="color:darkblue">Change security question</a>
</br>
</br>
<body>
<form method ="POST">
<h4>Age:</h4>
<input type="age" class="form-control" name="age" id="ageinput" value="<?php echo $row['age']; ?>">
<h4>Location:</h4>
<input type="location" class="form-control" name="location" id="locationinput" value="<?php echo $row['location']; ?>">
<h4>Favourite beer:</h4>
<input type="beer" class="form-control" name="favouritebeer" id="beerinput" value="<?php echo $row['favouritebeer']; ?>">
<h4>Website:</h4>
<input type="website" class="form-control" name="website" id="websiteinput" value="<?php echo $row['website']; ?>">
<h3>Bio: </h3>
<input type="bio" class="form-control" name="bio" id="bioinput" value="<?php echo $row['bio']; ?>">
保存更改
</form>
</div>
如果从视图调用此editProfile函数,请尝试以下代码: 鉴于:
<a href="<?php echo base_url()/controller/editProfile/<?php echo $id;?>">edit </a>
如果您是从同一控制器中的另一个函数调用此函数,请尝试以下操作:
$this->editProfile(1);
您的意思是表单没有在编辑页面上填充,但它以某种方式提交,我根本无法访问该页面。当我从控制器中的editProfile$id中删除$id时,我可以访问它。表单中填充了数据,但当我单击submit时,它会给我未定义的变量:id。codeigniter也有自己的数据库库,您可以自动加载它。还可以使用model获取项目,您可以共享调用editProfile函数的代码吗
function editProfile() {
$id = $this->uri->segment(3);
// do more
}
$this->editProfile(1);