Jump to content

Overriding Frontcontroller


lordanthony

Recommended Posts

Hi,

 

I need to add some global smarty variables to be used throughout the site and would like to override FrontController.php to bring in the extra data.

I am able to adjust the main FrontController.php to do whis but when I try to move the code in to the proper override location I get a blank screen.

I'm adding the code to the init() function.

 

 

Could anyone tell me what the correct way to do this is?

These are the additional variables I need:

 

		$smarty->assign(array(
		'petname' => $result['name'],
		'animaltype'=>$result['relationship'],
		'birthday'=>$result['day'].".".$result['month']
))

 

Many thanks

Link to comment
Share on other sites

If you override the function, you need to copy the whole thing over to your overriden class. If you only add your code to it, the code from the original class doesn't get executed.

 

So basically nothing gets executed apart from your assign so you're getting a blank page, imho.

Link to comment
Share on other sites

The syntax of the override file is different, you can't just copy the same file there.

 

it should look like

 

<?php

class FrontController extends FrontControllerCore
{
public function init()
{
               self::$smarty->assign(array(
                       'petname' => $result['name'],
                       'animaltype'=>$result['relationship'],
                       'birthday'=>$result['day'].".".$result['month']
	parent::init();
}
}

This will add you code and also execute the existing init() code.

  • Like 2
Link to comment
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
×
×
  • Create New...