我正在使用CodeIgniter,並有問題發送變量使用$ this-> load-> view('註冊',$ data)。Codeigniter傳遞變量錯誤
這是我的控制器中的一些代碼。
function create_member()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('password1', 'Confirm Password', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE)
{
$this->load->view('signup');
}else
{
$this->load->model('membership');
if($query=$this->membership->check_username() == TRUE)
{
$data['msg']= "Username exist";
$this->load->view('signup',$data); //problem encounter here.
}else
{
if($query = $this->membership->create_member())
{
$data['main_content'] = 'signup_successful';
$this->load->view('include/template', $data);
}else
{
$this->load->view('signup_form');
}
}
}
}
而且這裏的錯誤消息: 一個PHP錯誤遇到
嚴重性:注意
消息:未定義的變量:味精
文件名:觀點/ signup.php
行號:99
<?php echo $msg; ?> // code inside view/signup.php
謝謝,你說得對,我必須在開始時將$ data ['msg']初始化爲空:) – 2012-03-02 22:09:25