Jump to content

Overriding Frontcontroller Based On The Http_Referer


lafondadebaco
 Share

Recommended Posts

I saw on the excelent article of the blog: http://www.prestashop.com/blog/article/modules_classes_and_controller_override_by_julien_breux/ the following example (Example 4 on the article).

 

/*
* with this override, you have a new smarty variable "currentController"
* available in header.tpl
* This allows you to use a different header if you are
* on a product page, category page or home.
*/
class FrontController extends FrontControllerCore{
 public function displayHeader()
 {
   self::$smarty->assign('currentController',get_class($this));
   return parent::displayHeader();
 }
}

 

I would like to know if it is possible to use the override based on the HTTP_REFERER variable.

 

Does anybody knows how I can make this?

 

Thanks

Share this post


Link to post
Share on other sites

All you would need to do is change the above to :

 

class FrontController extends FrontControllerCore{
 public function displayHeader()
 {
   self::$smarty->assign('currentController',get_class($this));    
   self::$smarty->assign('currentReferrer',$_SERVER['HTTP_REFERER']);
   return parent::displayHeader();
 }
}

 

Now you have 2 variables in the header.tpl file to test to determine which header to use ;)

 

The only problem is that the $_SERVER['HTTP_REFERER'] variable isn't very reliable and can easily be spoofed, so I would suggest you might need to clean it up rather than just pass it directly as in the example above. It also may or may not be set at all... The WP Greet Box plugin for Wordpress might be good for some inspiration.

 

Paul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More