Hi, I'm new in this forum and need some advice regarding to solve my problem. Here I'm using CI 2.2.2 and have 2 controllers, in main controller (dashboard) I have code to get list of projects:
PHP Code:
class Dashboard extends MY_Controller {
function __contruct()
{
parent::__contruct()
$project_id = array('projectid' = '');
// remove project id session userdata
$this->session->unset_userdata($project_id);
}
function index()
{
$this->load->model("content_model");
// getting project list
$this->data['projects'] = $this->content_model->get_content();
// rendering view
$this->_render_page('dashboard/index', $this->data);
}
}
and here is my dashboard index view:
PHP Code:
<html>
<?php foreach ($projects as $project):?>
<?php echo anchor("projects/index/".$project->id, 'Project', 'title="List Project"');?>
<?php endforeach;?>
</html>
above code will generate links to projects controller as shown below:
PHP Code:
<a href="http://me.com/projects/index/1" title="List Project">Project</a>
<a href="http://me.com/projects/index/2" title="List Project">Project</a>
<a href="http://me.com/projects/index/3" title="List Project">Project</a>
1, 2, 3 ..etc is ids of projects, so in my second controller I set this ids to session userdata:
PHP Code:
class Projects extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->model("project_model");
}
function index($projectid = NULL)
{
// checking for id
if ($projectid !== null && !is_numeric($projectid))
{
header("refresh:4;url=".base_url('dashboard'));
return show_404();
}
// set project ids to session userdata
$ses = array('projectid' => $projectid);
$this->session->set_userdata($ses);
// querying get data of project
$this->project_model->data_project($projectid);
}
}
After set this ids to userdata it will be easy to me querying data related projects from database:
Code:
// get project id from session
$projectid = $this->session->userdata('projectid');
// querying save goods to related project
$this->project_model->add_goods_project($projectid, $form_data);
// querying remove goods from related project
$this->project_model->remove_goods_project($projectid, $goodid);
But this method will not effective if user open multiple projects link in diffrent tabs, it will mess up querying to database, since session only support one data.
If I set userdata as variabel:
Code:
$ses = array($projectid);
$this->session->set_userdata($ses);
It make me confused how call this userdata in other functions, since I don't know which ids projects user have.
I need someone suggest me (advise) a better method so user can enjoy open multiple projects?
Thanks