Domanda

I am using SS 3.02 and have made a lots of modification in the core files. I am facing the issue that I am trying to set the color of the navigation background dynamically. This works fine for pages other than security/login page. Suppose I am getting the value in $navbgcolor, this shows up well on home page or about us page or any other page. But this does not show up on the Security/login page. Any help would be greatly appreciated. Thanks.

È stato utile?

Soluzione

Firstly, it is never a good idea to alter the core files as this prevents you from easily updating your version of SilverStripe. You could miss out on bug fixes and important security updates.

The reason this isn't working on the login page is because the login page works from the Security controller which directly extends Controller. Your code (presumably in Page_Controller) will be completely bypassed.

Here is a way you could apply your code to all controllers, without touching the core:

<?php

class MyControllerExtension extends Extension {

    public function onAfterInit() {
        //... Your code here...
    }

}

In your config file you would apply your new controller extension to Controller.

If you're using _config.php

Object::add_extension("MyControllerExtension", "MyControllerExtension")

If you're using YAML (recommended)

Controller:
  extensions: 
    - 'MyControllerExtension'

You can learn more about extensions here: http://doc.silverstripe.org/framework/en/reference/dataextension

Altri suggerimenti

Also to let you know, you can create specific template file for the Security login pages by creating action sub-templates. Example is if you created a file in your theme called "Security_login.ss" you can call in variable, change the mark up etc.

Note the convention here is the filename is called the name of the class in this case "Security" then "_" followed by the name of the action to be rendered by your controller ("login" in this case).

As mentioned by micmania1, the golden rule for developing in SilverStripe is...

"Don't hack the core or modules!"

Instead as pointed out use extensions to decorate classes, or use subclasses if you have to.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top