[eluser]Jareish[/eluser]
Hi,
I have a page in my CMS which consists of different parts. For instance you can add a category in 1 sidebar, and edit settings in another.
Adding a category goes through a different function then saving settings. And thus generates other error feedback.
My controller looks something like this
Code:
<?php
class Projects extends Controller {
function __construct()
{
parent::Controller();
$this->load->model('projects_model');
}
function index()
{
redirect('site/members_area');
}
function editProject(){
$data['title'] = 'title';
$data['projects'] = this->projects_model->getProject();
$data['main_content'] = 'projects/editProject';
$this->load->view('includes/template', $data);
}
function addCategory()
{
//add to db
if(this->projects_model->addCategory())
{
//success
$data['message'] = "succesfully added"
}
else {
//failed
$data['message'] = "failed"
}
//ok this is the part where I want $data['message'] in editProject and load the editProject view.
}
}
?>
when you click on a project on the members page, it loads the editProject function, loading lots of stuff from the database, everything stored in $data.
What I want to do is, when I add a category, to send the $data['message'] to the editProject function because I don't want to load all the same stuff in the addCategory fucntion. I don't want to do this with a function parameter, because the editProject function has to work without it. So the best way would be (I think) is to set a variable in the controller, then use a redirect in the addCategory function.
the editProject() would read that variable from the controller (or leave it empty if nothing is in it). and send it to the corresponding view.
I've seen alot of tutorials, but from what I've seen, they all do a redirect to a different view on success/fail. But I want it to be the same view, with a reserverd Div for errors.
I've read stuff on the forum about adding a global $message in the constructor, and then again in every function you use
Code:
global $message;
$data['message'] = $message;
I then got something like this:
Code:
<?php
class Projects extends Controller {
function __construct()
{
parent::Controller();
$this->load->model('projects_model');
global $message;
}
function index()
{
redirect('site/members_area');
}
function editProject(){
global $message;
$data['message'] = $message;
$data['title'] = 'title';
$data['projects'] = this->projects_model->getProject();
$data['main_content'] = 'projects/editProject';
$this->load->view('includes/template', $data);
}
function addCategory()
{
//add to db
global $message;
if(this->projects_model->addCategory())
{
//success
$message = "succesfully added"
}
else {
//failed
$message = "succesfully added"
}
//ok this is the part where I want $data['message'] in editProject
redirect(.... etc)
}
}
?>
But I still get and error (not defined). Any ideas what Im doing wrong?