This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

filter question

Discussion around this tutorial for symfony 1.0.x

filter question

by kaancho » Tue Dec 09, 2008 8:35 am

Hi,
I am testing waters with the custom filters and had some problems.

my filter.yml file looks like this:

rendering: ~
web_debug: ~
security: ~
rememberFilter:
class: rememberFilter

my rememberFilter class looks like this:

<?php
class rememberFilter extends sfFilter
{
public function execute($filterChain)
{
}
}

?>

However I get a blank page when I now go to my homepage. There is no error in the error log.

I did have this in the filterclass

if("some criteria")
{
// execute this filter only once
if ($this->isFirstCall())
{
// do things
return $this->getContext()->getController()->forward('default','index');
}
}

but this also doesnt work. Any idea what I might be doing wrong?

Thanks
ko
kaancho
Junior Member
 
Posts: 7
Joined: Tue Jun 24, 2008 5:08 am

Re: filter question

by skywalker » Tue Dec 09, 2008 3:49 pm

Your class should look like this:

Code: Select all
class rememberFilter extends sfFilter
{
  public function execute($filterChain)
  {
    // your stuff goes here...

    $filterChain->execute();

    // or here, depending on the purpose.
  }
}


If you don't have the $fileterChain->execute(), you will probably get an empty page.

I'm not sure you can do a forward in a chain.
May the source be with you
User avatar
skywalker
Faithful Member
 
Posts: 337
Joined: Fri Mar 07, 2008 4:31 pm
Location: Norway

Re: filter question

by kaancho » Tue Dec 09, 2008 5:22 pm

Hi,
Thanks for your reply.
It works.

It works correctly, however when I do this

return $this->getContext()->getController()->forward('default','index');

it renders the page twice on that page. Something to do with rendering but cant pin point why. Any idea?

Thanks
kaancho
Junior Member
 
Posts: 7
Joined: Tue Jun 24, 2008 5:08 am

Re: filter question

by kaancho » Tue Dec 09, 2008 5:24 pm

Hi,

I changed my filter to look like this:

rememberFilter:
class: rememberFilter
rendering: ~
web_debug: ~
security: ~

from:

rendering: ~
web_debug: ~
security: ~
rememberFilter:
class: rememberFilter

and so it does the redirect before rendering. Am i doing it right?

Thanks
kaancho
Junior Member
 
Posts: 7
Joined: Tue Jun 24, 2008 5:08 am

Re: filter question

by Russpd » Sat Feb 14, 2009 6:52 pm

I had the same issue and solved the problem the same way. I was wondering if that is a bad solution. I don't want to mess up the order of the filterchain and am worried that there was some emphasis in some of the literature of how the rendering filter needs to go first. However, with forwards you end up getting the content displayed twice on the page (and a whole bunch of errors) unless you use the method described above
Russpd
Senior Member
 
Posts: 105
Joined: Wed Sep 03, 2008 9:46 pm

Re: filter question

by skywalker » Mon Feb 16, 2009 11:44 am

Check the function isFirstCall():

Code: Select all
class myFilter extends sfFilter
{
  public function execute($filterChain)
  {
    if ($this->isFirstCall()) {
      // do some stuff.
    }

    $filterChain->execute();
  }
}
May the source be with you
User avatar
skywalker
Faithful Member
 
Posts: 337
Joined: Fri Mar 07, 2008 4:31 pm
Location: Norway