[eluser]Unknown[/eluser]
Hello everyone!
I'm new to the codeigniter framework and I'm impressed of how fast you can write code with it! The only problem I have is the following and I hope there is a good way to solve it!
I will keep it simple so let's say I have 2 controllers (login.php & site.php) and 1 view (home.php).
site.php
Code:
<?php
class Site extends Controller {
function index()
{
$data['a'] = 'example';
$data['b'] = 'test';
$this->load->view('home.php', $data);
}
}
login.php
Code:
<?php
class Login extends Controller {
function index()
{
// Run form validation and if ok do the following
redirect('site');
//else
$data['a'] = 'example';
$data['b'] = 'test';
$this->load->view('site', $data);
}
}
home.php
Code:
html code + form that posts to login.php
My problem is that because the form posts the data to the login.php controller, (if the validation fails and I want to show the errors) I have to load the view again and enter the array $data again because it is essential to the view.
In this case it's ok because this is a small array. But what if I have a view which requires a lot of data (and some of them is from a database!). I have to recreated the data every time I want to load a view from a different controller? Is there a way to load the view by calling the site/index and keep intact the form validation messages?
Thanks in advance.. I hope there is an easy solution to this!