CodeIgniter Forums
Admin for more than one site? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Admin for more than one site? (/showthread.php?tid=49085)



Admin for more than one site? - El Forum - 02-07-2012

[eluser]rudejason[/eluser]
Hope I am putting this question in the right place.

As some of you know I have been working on several websites for one client. Now I am building an admin system for them to handle all the site. I have seen several posts where you can switch config or database files by using the domain your on. I am not able to do that. The admin will be on one domain. All the sites are hosted on the same server so I am able to connect to all the databases from one domain.

They all have the same database structure just different data.

There are 4 total databases.

main <-- holds the users and other internal stuff
site1
site2
site3

in my database.php file (config folder) I have set up 4 groups

default (main)
site1
site2
site3

Here is how it is working so far.

User goes to the admin, the default / main database loads.
During login the code checks to see what the last site was they were working on and sets a session var using set_userdata with that value.

Now logged in, the user sees a select menu with the current site (set in the session from the main db on login)

When they change the selector to a different site, i use ajax to change the session var and update the db. Doing so i use
Code:
$this->db->query();
and it is working fine.

The page reloads and the new selection shows and the session var is set to the new site / database.

Now on the pages where i pull information / edit / add etc.. i use the following code

Code:
$editdb = $this->session->userdata('editdb');
$CI =& get_instance();
$CI->$editdb = $this->load->database($editdb, TRUE);
$this->$editdb =& $CI->$editdb;

Then to make the sql calls i use
Code:
$this->$editdb->query();

The issue comes when I want to use flash data. So say the user edits and item, well i want them to know the item was edited.
So i set flash data like so

Code:
$this->session->set_flashdata('msg','Update Success');
I then use the redirect with refresh set.

On the next page i check for the flashdata like so
Code:
If($this->session->flashdata('msg'))

But it never shows...

I am thinking it is because i have my sessions set to use the database. There are ways around it, i could use Cookies to pass the success or fail message but would like to keep everything consistent and well i seem to have no luck with the set cookie stuff in Codeigniter. My cookies never set...
If i use the php method of setcookie they work fine.

So I am guessing that what ever site is selected, that is the database the sessions are set to.

Any ideas on how to get my flash data to work across all the sites / databases?

Should i store the session localy and not in the database?

It is not a big cookie, userid(int), name, user type (int), logged in, selected site.

Thanks in advance.



Admin for more than one site? - El Forum - 02-07-2012

[eluser]rudejason[/eluser]
Ok guess i should have tried that before asking...

I changed my sessions to NOT use the database and now my flash data is working fine.