csy_dot_io
csy_dot_io

Reputation: 1199

Empty route leeds to 404-Error - SilverStripe 3.5

Like superficial descriped in SilverStripe Docs, I'm trying to set a custom controller for my homepage.

I changed the default homepage link to 'custom-home' and added those two routes. The second one, with the path in it works and directs me to my controller. The first (empty) one just sends me to an 404-error page.

Couldn't figure out how to fix that. Any suggestions?

routes.yml

Director:
  rules:
    '': 'MyHome_Controller'
    'custom-home': 'MyHome_Controller

_config.php

RootURLController::set_default_homepage_link('custom-home');

MyHome_Controller.php

<?php
class MyHome_Controller extends Page_Controller {

  private static $allowed_actions = [];

  private static $url_handlers = [];

  public function init() {
    parent::init();
  }

  public function Link($action = null) {
    return Director::baseURL() . 'custom-home';
  }

  public function index() {
    $data = [
      'Title' => 'Hello World',
      'ClassName' => __CLASS__,
    ];

    return $this
      ->customise($data)
      ->renderWith([__CLASS__, 'Page']);
  }

}

Upvotes: 1

Views: 120

Answers (1)

UncleCheese
UncleCheese

Reputation: 1584

I believe the way the empty route (RootURLController) works is that you're telling it the URLSegment of a page in the CMS that should resolve to the root URL. So I think what you need to do is go into the CMS and change the URLSegment of your CustomHomePage to 'custom-home'.

Upvotes: 0

Related Questions