[eluser]newbrand[/eluser]
Hi there,
Another silly question from a beginner. So this is a pretty common thing that I guess most people may experience. I've done it the same way for a long time, perhaps it's time to change it up.
On certain scripts I have a number of "responses" that are handled by the view script. What I typically do is set a variable to display a certain response, pass it to the view and let it figure out the rest.
I should note that I'm also using the Template Class that a user suggested on the forums.
Take a look:
Code:
<?php
class EditAccount extends Controller {
function EditAccount() { parent::Controller(); }
function index()
{
$this->load->library('form_validation');
$this->load->library('template');
$this->load->library('session');
$view = array();
if ($this->session->userdata('display') == "")
{
$view['notloggedin'] = true;
} else {
if (isset($_POST['register']))
{
if ($this->form_validation->run() == true)
{
}
}
}
$this->template->parse_view('content', 'editaccount', $view);
$this->template->render();
}
}
?>
Line 14, I'm checking if they are logged in. If they aren't I set a view variable and the view handles the readout. Else anything after line 18 performs the functions once the user is logged in. This is a more specific case, but generally I have a range of responses to give to the user. I categorise them as "errors", "success", and "warnings".
Here is a sample of a view script I have created:
Code:
<div id="register">
<?php
if (isset($notloggedin)) {
echo "<div id='error'>You are not logged in! Login to view this page.</div>";
} else {
if (isset($success))
{
echo "<div class=\"success\">{$success}</div>";
} else {
?>
<?php echo validation_errors(); ?>
<form action="/editaccount/" method="POST">
<h3>First Name</h3>
<input type="text" name="firstname" value="<?php echo set_value('firstname'); ?>">
<h3>Last Name</h3>
<input type="text" name="lastname" value="<?php echo set_value('lastname'); ?>">
<h3>Password</h3>
<input type="password" name="pass" value="<?php echo set_value('pass'); ?>">
<h3>Confirm Password</h3>
<input type="password" name="passconfirm" value="<?php echo set_value('passconfirm'); ?>">
<br><br>
<input type="submit" name="edit" value="Edit Account">
</form>
<?php } } ?>
</div>
Basically checks for certain logics and continues to display the correct message. I don't really need this flexibility and I feel as if it may be wrong somehow. Anyone have a better method/suggestion.
Regards,
Dave