我想知道是否有人可以告诉我他们如何处理CodeIgniter中的成功/失败消息.
例如,当用户注册我的网站时,我正在做什么,这就是控制器中发生的事情
if (!is_null($data = $this->auth->create_user( $this->form_validation->set_value('username'), $this->form_validation->set_value('password') ))) {
// Redirect to the successful controller
redirect( 'create-profile/successful' );
} else {
// Redirect to the unsuccessful controller
redirect( 'create-profile/unsuccessful' );
}
Run Code Online (Sandbox Code Playgroud)
然后在同一个控制器(创建配置文件)中,我有2个方法,如下所示
function successful()
{
$data['h1title'] = 'Successful Registration';
$data['subtext'] = '<p>Test to go here</p>';
// Load the message page
$this->load->view('message',$data);
}
Run Code Online (Sandbox Code Playgroud)
这个问题是我可以直接访问site.com/create-profile/successful并显示该页面.
如果有人能够告诉我更好的处理方式,我们将不胜感激.
干杯,
小智 6
您可以在重定向之前设置flashdata:
$this->session->set_flashdata('create_profile_successful', $some_data);
redirect( 'create-profile/successful' );
Run Code Online (Sandbox Code Playgroud)
function successful(){
if( FALSE == ($data = $this->session->flashdata('create_profile_successful'))){
redirect('/');
}
$data['h1title'] = 'Successful Registration';
$data['subtext'] = '<p>Test to go here</p>';
// Load the message page
$this->load->view('message',$data);
}
Run Code Online (Sandbox Code Playgroud)
有没有理由你不使用这个:
if (!is_null($data = $this->auth->create_user( $this->form_validation->set_value('username'), $this->form_validation->set_value('password') ))) {
$data['h1title'] = 'Successful Registration';
$data['subtext'] = '<p>Test to go here</p>';
// Load the message page
$this->load->view('message',$data);
} else {
$data['h1title'] = 'Unsuccessful Registration';
$data['subtext'] = '<p>Test to go here</p>';
// Load the message page
$this->load->view('message',$data);
}
Run Code Online (Sandbox Code Playgroud)
迎接,斯特凡
| 归档时间: |
|
| 查看次数: |
23743 次 |
| 最近记录: |