Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Routing is coming up as Page not found


Go to End


3 Posts   1474 Views

Avatar
hschillig

Community Member, 5 Posts

5 February 2015 at 4:31am

Edited: 05/02/2015 7:43am

I have two routes that I'm working on. One of them works and one of them does not. The UserEducation_Controller route works fine, but the UserEmployment_Controller does not. Here is my code:

http://pastebin.com/09xmfhr4

This is what is my routes.yml file:

---
Name: userroutes
After: framework/routes#coreroutes
---
Director:
    rules:
        'user/education' : 'UserEducation_Controller',
        'user/employment' : 'UserEmployment_Controller',
        'user' : 'User_Controller'

---
Name: jobroutes
After: framework/routes#coreroutes
---
Director:
   rules:
      'job' : 'JobPosting_Controller'

This is my UserEducation.php file:

class UserEducation_Controller extends Page_Controller {

    private static $allowed_actions = array(
        'add', 
        'edit' => '->isOwner', 
        'remove' => '->isOwner', 
        'UserEducationForm', 
        'doAdd'
    );

    private static $url_handlers = array('edit/$ID' => 'index', 'add' => 'index');

    // INSERT NEW EDUCATION ENTRY
    public function index()
    {
        $backUrl = $this->request->getVar('BackURL');

        // If register success
        if( $this->request->getVar('success') == 1 )
        {
            // Form submission was successful so redirect to BackURL
            return $this->redirect( $backUrl );
        }

        return $this->renderWith(array('UserEducation', 'Page'));
    }
}

This is my UserEmployment.php file:

class UserEmployment_Controller extends Page_Controller {

    private static $allowed_actions = array(
        'add', 
        'edit' => '->isOwner', 
        'remove' => '->isOwner', 
        'UserEmploymentForm', 
        'doAdd'
    );

    private static $url_handlers = array('edit/$ID' => 'index', 'add' => 'index');

    // INSERT NEW EMPLOYMENT ENTRY
    public function index()
    {
        Requirements::css('themes/simple/datetimepicker/jquery.datetimepicker.css');
        
        $backUrl = $this->request->getVar('BackURL');

        // If register success
        if( $this->request->getVar('success') == 1 )
        {
            // Form submission was successful so redirect to BackURL
            return $this->redirect( $backUrl );
        }

        return $this->renderWith(array('UserEmployment', 'Page'));
    }
}

I tried switching the placement of the routes so the employment one comes first and then didn't change anything. The result is the same (education works, employment does not).
I created a public function init() method in my employment and did a die() statement in there and that didn't even hit so I'm guessing it's not even hitting the controller.

Any ideas? Thanks.

EDIT:
I even tried putting useremployment instead of user/employment to see if it was the nesting causing the problem and it still wouldn't work when I navigated to mysite.com/useremployment/add. I did the same with the usereducation and it still worked fine.. did a flush and dev/build.

Avatar
hschillig

Community Member, 5 Posts

6 February 2015 at 7:35am

Anybody have any ideas on this? Thanks..

Avatar
thomas.paulson

Community Member, 107 Posts

9 February 2015 at 3:30pm

Edited: 09/02/2015 3:40pm

I think you are missing '$Action' parameter in routing file, check the link for more info http://doc.silverstripe.org/en/developer_guides/controllers/routing/
---
Name: userroutes
After: framework/routes#coreroutes
---
Director:
rules:
'user/education//$Action/' : 'UserEducation_Controller'
'user/employment//$Action/' : 'UserEmployment_Controller'
'user' : 'User_Controller'

also stripe out comma ',' at the endof the 'user/education' : 'UserEducation_Controller',