Welcome Guest, Not a member yet? Register   Sign In
Make a more robust Request Cache
#1

[eluser]j2more[/eluser]
I am coming from a java background and I really miss the Page/Session/Application Cache concepts in CI and PHP generally.

One quite typicall example of this PHP / CI weakness is the flashdata. It says:

/**
* Sets "flash" data which will be available only in next request (then it will
* be deleted from session). You can use it to implement "Save succeeded" messages
* after redirect.
*/

you realize the significant wording "only for the next response" this is to be understood exacly as its written, only for the next request, but not within the same request.

What about situations where you would just like a convinient way to return multiple Objects from a method but.

So I added this little utility to the Session class:

function set_samereq_flashdata($key, $value)
{
$flash_key = $this->flash_key.':old:'.$key;
$this->set_userdata($flash_key, $value);
}


Feedback welcome..
#2

[eluser]jedd[/eluser]
Why don't you just return an array of objects?
#3

[eluser]j2more[/eluser]
Because sometimes this is not an elegant solution. Eg. you return already an array or you want to use the object way later in the code without passing it along all the invocation graph.
#4

[eluser]jedd[/eluser]
[quote author="j2more" date="1255821032"]
What about situations where you would just like a convinient way to return multiple Objects from a method but.
[/quote]

[quote author="j2more" date="1260858373"]
Eg. you return already an array ...
[/quote]

Return already? I thought you were talking about a situation where you want to return multiple objects from a method? If you are happy to call multiple methods to get individual objects on each call, then, yeah, sure, why not. Doesn't seem very elegant to me, though.

Quote:...or you want to use the object way later in the code without passing it along all the invocation graph.

An array of objects means you can easily extract / copy / use the object that came back inside the array (of objects).

I still believe this is a cleaner approach than subverting the return $value mechanism by wedging some data into the Session space in the model, then looking for it later in the controller.

If you want to go a bit more OO, then have the model populate a bunch of attributes, and then refer to them from the controller.




Theme © iAndrew 2016 - Forum software by © MyBB