Welcome Guest, Not a member yet? Register   Sign In
Site-wide variables not available in controller/model files
#3

(03-16-2016, 12:10 PM)Narf Wrote:
(03-16-2016, 11:13 AM)bg17aw Wrote: 1) Is it good practice to pass data around using $_SESSION? I don't really like it, I would rather have them loaded from file like it happens in the non-admin (non-CI) area of the website

No.

(03-16-2016, 11:13 AM)bg17aw Wrote: 2) Is it good practice to add those lines to 'index.php' file?

No, and that wouldn't work anyway - they'd be outside of the controller's scope.

(03-16-2016, 11:13 AM)bg17aw Wrote: 3) Is it good practice to start the session this way (and in that location, again index.php)?

No.

(03-16-2016, 11:13 AM)bg17aw Wrote: 4) Is the controller code above the right way to go?

No, and you don't need that 'php_session' thing at all.

-----------------------------------

Easiest way is to use constants, because they aren't affected by scope visibility.

Thanks for your answer, but I have to say I was hoping for more info on how to achieve the desired effect, and why it is not good practice, not just that it is not.

session_start() in index.php works, from what I can see, and all the code I pasted above works.
Why do you say it won't work? 

Why don't I need 'php_session' ? How can I can the session variables without using php_session?

About defining constants: there would be a lot of them and not sure that would be good practice wither, I never seen this approach in any code I inspected. 

If you can elaborate a bit on your answers, why I should not put session_start in index.php, where should I put it (I definetely need the session started at some point, as the login took place already so the user data is in the session), how can I get session data without php_session etc I would really appreaciate it. 
I tried searching and googleing on this issue and some were recommending the Session approach, which you say it is not a good idea. Confused now... However, so far, the code above is working fine in production.
Reply


Messages In This Thread
RE: Site-wide variables not available in controller/model files - by bg17aw - 03-18-2016, 03:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB