Welcome Guest, Not a member yet? Register   Sign In
Array global between Controllers - Problem.
#11

[eluser]Jinme[/eluser]
I'm sorry to cause you so much trouble, but the code is the same, I thinked is not real necessary publish all at the first time. I'm not change the code, it's complemented for your understanding.

The initial idea (if can be possible) was used a array (global) for read permissions in a ACL, and not load anytime this from database, only one time from a initial Controller.

It's is only possible if can be global between all Controllers in my application or accesible to Acl Class library? or not?

The intention is publish that library for other people and not complicate.

Some idea for continue?

P.D. Sorry again, it's not my intention you trouble.
#12

[eluser]n0xie[/eluser]
You can't store the array in the library between requests. It will forget everything on the next request.

So either you make a database connection on each request, or you find some other means to save the array (memory, file, database in memory).
#13

[eluser]Jinme[/eluser]
Thanks n0xie, any suggestion for save the array with the permissions in memory? it can be long, for that Session it's not a good idea. I think.-
#14

[eluser]n0xie[/eluser]
I would start just using a cache file. Phil Sturgeon's Cache Library could be useful here.

If you want in memory storage I'd suggest you take a look at Memcached or Redis

But I do have to ask, what is so terrible about doing a database lookup on each request?
#15

[eluser]Jinme[/eluser]
Good question! nothing wrong really, but the intention was to make it more generic, is more flexible to other users implement the Class if it is independent from a database.

But I see it is almost impossible implement my initial idea. Tongue

Thanks, really.
#16

[eluser]skunkbad[/eluser]
What is wrong with storing data in the real $_SESSION array?
#17

[eluser]Jinme[/eluser]
Use Session is not a good idea for a array (it can be long). Note from UserGuide: Cookies can only hold 4KB of data.
#18

[eluser]WanWizard[/eluser]
Using cookies to store your session information is not a good idea.

First, because of this size limitation,
second, because of cookie issues with some browsers,
third, because this cookie is send back and forth with every request, thus using bandwidth and slowing your application down, and
fourth, you don't want to store any sensitive information client side. Ever. Encrypted or not.

If you are concerned about database performance (you shouldn't), you can always create a RAM disk, and use file I/O to store the array serialized, or even use native PHP sessions and store them on the RAM disk...

Having said that, there is definately room for some optimization in CI's session handling.

The standard library updates the database every time you use set_userdata(). I use a MY_Session library to alter that behaviour, I only update the session once, at the end of every page request. If you do that, remember that a redirect() causes a loss of session info, so either update the session manually, or update the URL helper to do an session update before a redirect.




Theme © iAndrew 2016 - Forum software by © MyBB