views:

426

answers:

5

Hello,

I'm using the setFlash and hasFlash methods of symfony 1.4 with WAMP 2.0

Locally with my frontend_dev app, all work fine. But in production environment, my test $this->forward404Unless($user->hasFlash('resultsArray')); fails.

I thought that the flash methods where enabled by default. What can I do to make it works please ?

Thanks in advance,

Gaff.

Edit : I found an interesting error message.

Here is my filters.yml file

# You can find more information about this file on the symfony website:
# http://www.symfony-project.org/reference/1_4/en/12-Filters

rendering: ~
security:  ~

# insert your own filters here

cache:     ~
flash:     ~
execution: ~

In the frontend_prod.log, I have :

Mar 16 05:57:42 symfony [info] {sfPatternRouting} Match route "homepage" (/) for / with parameters array (  'module' => 'main',  'action' => 'index',)
Mar 16 05:57:42 symfony [err] {sfParseException} Configuration file "D:\wamp\bin\php\symfony\symfony14\lib/config/config/filters.yml" specifies category "flash" with missing class key.
A: 

Not sure if this is the answer, but I don't have a flash key in my filters.yml file, in a Symfony 1.4.3 app, and I haven't touched it since grabbing the version from the Symfony site. Have you tried removing that line from the yml file, clearing your cache and trying again?

richsage
You're right. I've put it after encoutering the problem (and it gave me the "specifies category "flash" with missing class key." message). It was only a dumb test. Sorry. I've removed it but like before, it still don't work.
Gaff
A: 

@Lunohodov

(Sorry for posting an answer instead of a comment but I can't use this way cause of the characters limitation)

Here is the action :

public function executeShowResult()
    {
        $user = $this->getUser();
        $this->forward404Unless($user->hasFlash('resultsArray'));

        $this->results = $user->getFlash('resultsArray');
        $user->setFlash('resultsArray', $this->results);

        $this->pager = new myArrayPager(null, 15);
        $this->pager->setResultArray($this->results);
        $this->pager->setPage($this->getRequestParameter('page'));
        $this->pager->init();

        $this->myModule = $this->getRequestParameter('myModule');
        $this->myTemplate = $this->getRequestParameter('myTemplate');

        $forwardPage = '../../'.$this->getRequestParameter('myModule').'/templates/'.$this->getRequestParameter('myTemplate');
        $this->setTemplate($forwardPage);

        return sfView::SUCCESS;

    }

Edit : Another interesting log. In my action which set the flash, I've put a log to test the set and hasFlash methods... and it worked :

$user = $this->getUser();
$user->setFlash('resultsArray', $this->results);

if ($user->hasFlash('resultsArray')) { sfContext::getInstance()->getLogger()->info("The flash is set"); } else { sfContext::getInstance()->getLogger()->info("The flash is NOT set"); }

The logs for that :

Mar 16 06:07:13 symfony [info] The flash is set

I think I'm missing something big here...

Gaff
A: 

Do you call the executeShowResult action in a redirect/forward context? The flash has a limited lifetime and it will disappear after the very next request. Clearly the resultsArray has been flushed out.

lunohodov
Or not since it works perfectly in dev environment (with the same code of course). I know this is weird and I have no more idea to clear this case.
Gaff
Agreed. I guess that doesn't explain why it doesn't work in the OP's dev environment but not in production though?
richsage
I mean, perhaps it has been cleared but why does it work in one environment and not in an other ?
Gaff
@Gaff: Do you set the flash and then redirect/forward to the *executeShowResult* action? Can you post your code?
lunohodov
Sorry, I missed that part of your message : "Do you call the executeShowResult action in a redirect/forward context?"Here is the way the page is displayed :1- submitAction which set in flash resultsArray2- submitSuccess.php page. It contains only this "<?php include_partial('common/showResult', array('pager' => $pager, 'myModule' => $myModule, 'myTemplate' => $myTemplate, 'results' => $results)) ?>"3- Moreover displaying the results, the _showresult.php page contains another partial for the pager : "_pagination" which has the links to the showResult action.
Gaff
@Lunohodov : there is no action involved in the process apart the first submit before the page is displayed. You can find below the code of the showSuccess action.
Gaff
@Gaff: It is still unclear to me. Please be more specific: how and where do you set the flash? how and where do you call *executeShowResult*?
lunohodov
Thanks to you lunohodov, I've got the real error : the plugin sfJqueryReloadedPlugin was correctly installed on my desktop but not on the development server. Thus when symfony loaded the jQuery helpers, it called an inexistant action and redirect to a 404 error. It was handled but this redirection flushed the flash. Here are the logs which helped me to find this (I don't really know why I had not post this before, I really sorry for that) :
Gaff
{sfPatternRouting} Match route "default" (/:module/:action/*) for /sfJqueryReloadedPlugin/js/plugins/jquery-ui-1.7.2.custom.min%27 with parameters array ( 'module' => 'sfJqueryReloadedPlugin', 'action' => 'js', 'plugins' => 'jquery-ui-1.7.2.custom.min\'',){myUser} Flag old flash messages ("resultsArray"){sfFrontWebController} Action "sfJqueryReloadedPlugin/js" does not exist{defaultActions} Call "defaultActions->executeError404()"To make it works, I've disabled the jQuery helpers in the app/config/settings.ymlThanks a lot to everyone who looked at this post, especially to Lunohodov.
Gaff
A: 

I wonder if you have caching enabled for prod?

If you do, and are caching with_layout (or if flash is in the action template, then caching the relevant action), then it will returned the cached page without the flash message on subsequent views.

benlumley