Welcome Guest, Not a member yet? Register   Sign In
Is this a cache problem?
#1

[eluser]scherman[/eluser]
Hi everyone, i have a serious problem with my backend. I think it is related with the cache.

I'll tell you an easy example of my problem, but you should know, my whole backend has the same problem.


For example, i have a CRUD of articles. Each article has a bool field (true=published; false=not published). My article's controller, render a list of all the articles. And next to the articles, you have a green button if the article is published (to unpublish it), and a red button if the article is unpublished (to publish it).

When i click on the red/green button, it redirects to this method:

(I use the WanWizard's Datamapper, but i think it won't be a problem tu understand)
Code:
public function publish($id, $state = true)
{
    if($id > 0)
    {
        $article = new Article();
        $article ->where('id', $id)->get();
        $article ->publicado = $state;
        $article ->save();
        redirect('backoffice/articles'); //return to the list again
    }
}

So, to the user experiencie, it should be: click the red button, the browser refreshs, and the button is green now.
But it doesn't work: i click the red button, the browser refreshs, and the button is still red.

If i check the database, i can see that it's worked! the article's state has changed. So, if i refresh the window (pressing F5), it load the new state.

It is very annoying to my clients who use my backend. Because, when they do some change, they have to refresh the window (pressing f5) to see the changes.


So, what can i do to solve it?

I will be very gratefull for your answers.
#2

[eluser]pbflash[/eluser]
Have you tried:

Code:
redirect('backoffice/articles','refresh');
#3

[eluser]scherman[/eluser]
Thanks for the reply, but it doesn't work
#4

[eluser]CroNiX[/eluser]
I think your problem is elsewhere. How are you detecting what color the button should be on that page?
#5

[eluser]scherman[/eluser]
[quote author="CroNiX" date="1328856927"]I think your problem is elsewhere. How are you detecting what color the button should be on that page?[/quote]

I do this on the view. Here is this part (i only put the structure, not the exactly code because if i add the anchor tags, it will renders here):
Quote:<?php if($article->publish): ?>
//render published.png (the green button)
<?php else: ?>
//render unpublished.png (the red button)
<?php endif ?>
#6

[eluser]CroNiX[/eluser]
How about set a flash session variable in your publish() method before you redirect. Then on the page with the button, check for that session variable. If it's not present (FALSE) show unpublished.png, if present show published.png. I suggest flashdata because it only lasts for the next server request and then deletes itself automatically.

BTW: your first sentence in the first post in this thread gave me a chuckle.
#7

[eluser]scherman[/eluser]
[quote author="CroNiX" date="1328858013"]How about set a flash session variable in your publish() method before you redirect. Then on the page with the button, check for that session variable. If it's not present (FALSE) show unpublished.png, if present show published.png. I suggest flashdata because it only lasts for the next server request and then deletes itself automatically.[/quote]

Thanks Cronix, but i want to figure out what is the problem, because i've put only an example, my whole backend has this problem, and i can't solve it with flashdata because i'll become crazy!

I think everyone else should have this problem also. And if nobody has it, it's because i'm doing all wrong!
#8

[eluser]CroNiX[/eluser]
Yep, but it's really hard to figure it out with that little bit of code
#9

[eluser]scherman[/eluser]
Yes, i know, but that's it. I think there is nothing weird about the code.
Also, when i use my backend local at my computer, it works fine! So, i think the code is not the problem.

Maybe i am doing something wrong with the redirect method... I don't know.




PLEASE HELP!
#10

[eluser]CroNiX[/eluser]
Instead of redirecting from that function, why not just return TRUE/FALSE since that is what you are checking for here:
Code:
<?php if($article->publish): ?>
  //render published.png (the green button)
<?php else: ?>
  //render unpublished.png (the red button)
<?php endif ?>




Theme © iAndrew 2016 - Forum software by © MyBB