I am not a professional, but I know my way around PHP, I am new to Codeigniter.
Looking through these guides: http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-5-crud/
OK, so I have a page that lists users, clicking on the username will go to the edit page, the URL of this page is index.php / users / edit / 1 (where 1 is the user ID)
There is a form on the editing page, this form contains several parts, each part is filled from different tables in the database. Therefore, my controller for editing looks like this:
function edit() {
$this->load->model('users_model');
$data['data_user'] = $this->users_model->getUser($this->uri->segment(3));
$data['data_user_password']= $this->users_model->getUserPassword($data['data_user'][0]->UserName);
$data['page_content'] = 'pages/users_edit';
$this->load->view('template/template', $data);
}
:
$data['data_user'] , , ,
$data['data_user_password']
, user_edit.php, .
, :
if (is_array($data_user)) {
foreach($data_user as $user)
{
$userID = $user->id;
$userName = $user->Name;
$userUserName = $user->UserName;
$userMail = $user->Mail;
$userDepartment = $user->Department;
$userWorkPhone = $user->WorkPhone;
$userHomePhone = $user->HomePhone;
$userMobile = $user->Mobile;
}
}
if (is_array($data_user_password)) {
foreach($data_user_password as $user)
{
$userPassword = $user->value;
}
}
Name:
<?php echo form_input('name', set_value('name', $userName), 'id="name" class="inputLong"'); ?>
, : index.php/users/update
:
function update() {
echo '<pre>';
print_r($_POST);
echo '</pre>';
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('pages/users_edit');
}
else
{
$this->index();
}
}
, form input = name id = name
, if ($ this- > form_validation- > run() == FALSE), , , , , - . , , post $, edit().
, validation_errors, :
Name .
, , , , PHP:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: userUserName
Filename: pages/users_edit.php
Line Number: 50