Im wondering if someone could let me know how they handle success / unsuccess messages in CodeIgniter.
For example, what im doing at the moment when a user signs up to my site, this is what happens in the controller
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' );
}
Then in the same controller (create-profile), i have 2 methods which are like the following
function successful()
{
$data['h1title'] = 'Successful Registration';
$data['subtext'] = '<p>Test to go here</p>';
// Load the message page
$this->load->view('message',$data);
}
The problem with this is that i can simply go to site.com/create-profile/successful and it will show the page.
If someone could possibly show me a better way of handling this, it would be greatly appreciated.
Cheers,
You could set a flashdata before the redirection:
$this->session->set_flashdata('create_profile_successful', $some_data);
redirect( 'create-profile/successful' );
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);
}
is there a reason you don't use this:
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);
}
greets, stefan
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With