Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>as you stated correctly, SilverStripe has routes, and they can be defined in a yaml config file. </p> <p>if you take a look at the existing <code>routes.yml</code> in the framework you can see how the default security route is defined: <a href="https://github.com/silverstripe/silverstripe-framework/blob/fd6a1619cb7696d0f7e3ab344bc5ac7d9f6cfe77/_config/routes.yml#L17" rel="nofollow">https://github.com/silverstripe/silverstripe-framework/blob/fd6a1619cb7696d0f7e3ab344bc5ac7d9f6cfe77/_config/routes.yml#L17</a></p> <p>if you just want to replace the <code>Secuirty</code> in <code>Secuirty/login</code>, its as easy as just creating your own <code>routes.yml</code>in <code>mysite/_config/</code> with the following content:</p> <pre><code>--- Name: myroutesorsomeotherrandomname Before: '*' After: - '#rootroutes' - '#coreroutes' - '#modelascontrollerroutes' - '#adminroutes' --- Director: rules: 'foobar//$Action/$ID/$OtherID': 'Security' </code></pre> <p><strong>NOTE</strong>: make sure you ran a ?flush=1 to ensure the yml file is loaded (they get cached)<br> also make sure you use spaces in the yml file, if you use tabs you are going to have a bad time</p> <hr> <p>if you however wish to also replace <code>/login</code> and <code>/logout</code> this is no longer a thing for routing.<br> login and logout are actions (php functions that are listed in Security::$allowed_actions and thus available as URL) on the on Security.<br> but its still rather easy, just subclass Security and create the actions you want:</p> <pre><code>&lt;?php class MySuperSecurity extends Security { private static $allowed_actions = array( 'showMeTheLoginForm', 'alternative_login_action_with_dashes', 'doTheLogout', ); function showMeTheLoginForm() { // can be visited via http://website.com/foobar/showMeTheLoginForm return $this-&gt;login(); } function alternative_login_action_with_dashes() { // can be visited via http://website.com/foobar/alternative-login-action-with-dashes return $this-&gt;login(); } function doTheLogout($redirect = true) { // can be visited via http://website.com/foobar/doTheLogout return $this-&gt;logout($redirect); } } </code></pre> <p>and make the route point to your new class instead of Security inside the <code>routes.yml</code>:</p> <pre><code> 'foobar//$Action/$ID/$OtherID': 'MySuperSecurity' </code></pre> <p><strong>NOTE</strong>: again, make sure you did a ?flush=1, both the <code>private static $allowed_actions</code> as well as the yml config file are cached by silverstripe.<br> <strong>NOTE</strong>: both solutions suggested in this post will create an additional route to login and does not replace the existing one, so the old <code>Security/login</code> will still be available</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload