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

Template for DataObjects hierarchy not working


Go to End


7 Posts   1204 Views

Avatar
okotoker

Community Member, 50 Posts

8 April 2016 at 2:10am

Edited: 01/07/2016 5:45am

So on 3.2.1 and before if I wanted to do this I would
add the route
create a "show" or similar function
have it return the customize info
create the template
and done I can now display my DataObject using getURLParameters().

If I try and do this in 3.3 I can't get the template to display. It just ignores it and uses the base page.ss template. If I downgrade to 3.2.1 and change nothing about my code it all works as expected.

I am assuming something changed along the way just not sure what.

Thanks for any help.

EDIT----
So it appears it has something to do with how I am routing as url_parameters works
routing looks like this
---
Name: myroutes
After: framework/routes#coreroutes
---
Director:
rules:
#'project//$Action/$ProjectID/$CustomerID': 'ProjectPage_Controller'

url parameters looks like this
private static $url_handlers = array(
'show/$ProjectID/$CustomerID' => 'show'
);

What am I doing wrong here with the route? I would prefer to use the route.yml instead of url_parameters.

-- EDIT SOLVED
My fault for not reading beyond what I thought was relevant to me ie routes.yml. It says in the docs under that part

You must use the $url_handlers static array described here if your URL pattern does not use the Controller class's default pattern of $Action//$ID/$OtherID. If you fail to do so, and your pattern has more than 2 parameters, your controller will throw the error "I can't handle sub-URLs of a class name object" with HTTP status 404.

Not sure why this worked previously and now I have to go this route but there it is.

Avatar
martimiz

Forum Moderator, 1391 Posts

13 April 2016 at 9:12pm

Looks like someone has a similar issue: http://www.silverstripe.org/community/forums/general-questions/show/111855#post413268

Maybe test this behaviour on a fresh install of 3.3.1 and if it's reproduced, downgrade to 3.2 to see if it persists? Should be quick and easy using composer...

Avatar
okotoker

Community Member, 50 Posts

14 April 2016 at 12:37am

Yes unfortunately I had tried that with no luck.

When I bounce back to 3.2 works upgrade to 3.3.1 and it breaks.

Annoying, but at least I can get what I need with url_parameters. Not my ideal but it is what I will use until I see some sort of fix or new version.

Thanks

Avatar
martimiz

Forum Moderator, 1391 Posts

14 April 2016 at 3:28am

In that case if you're sure it must be a bug (and if it works on 3.2 but not on 3.3, it just might be) then maybe you could create an issue for it on GitHub here:

https://github.com/silverstripe/silverstripe-framework/issues

Avatar
okotoker

Community Member, 50 Posts

19 April 2016 at 10:59am

As soon as I am done with the project I am actually having this issue on I will go back and start up a new project with just this one part set up and see if I can get it fixed. If I can't I will submit it.

I want to make 100% sure before I do that. I will just deliver this project with the url_parameters doing the work so I can wrap it up and deliver it.

I'll report back if I can't fix it.

Avatar
okotoker

Community Member, 50 Posts

17 June 2016 at 9:59am

Ok so I have beat my head into the wall on this one and I still haven't been able to sort it out. I tried doing a fresh install of 3.4 and then just adding one bit from a site that was working previously just fine on 3.2. It always pull the base page.ss instead of the correct template when I give it a route. If I comment out the route then it pulls the template just fine. If I use $url_parameters then it works fine is well, just the routes don't work. Just to pair it back to basics here is what I have.
routes.yml

---
Name: customroutes
After: framework/routes#coreroutes
---
Director:
  rules:
   'profile//$Action/$MemberURL/$MemberID': 'ProfilePage_Controller'
ProfilePage.php

<?php
class ProfilePage extends Page
{
private static $db = array(

);

private static $has_one = array();
}

class ProfilePage_Controller extends Page_Controller
{

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

private static $allowed_actions = array(
'show'
);

public function show($req)
{
$params = $this->getURLParams();
$user = SiteMember::get()->filter(array('ID'=>$params['MemberID']))->first();

return $this->Customise(array(
'User'=>$user
));
}
}


Then a template with a view items just to make sure that its looking at all the right things
<div class="row">
	<div class="columns large-12">
		<h1>Profile $ClassName $ID $URLSegment</h1>
	</div>
</div>

I cannot for the life of me figure out what is up. I have gone through all the new documentation and I can't find any changes that would affect the way I would do this. Its always worked for me before 3.3

Avatar
okotoker

Community Member, 50 Posts

1 July 2016 at 4:32am

Still looking for help. I started a fresh install of 3.4 in case there was a bug. I set up a test page and used just the simple default template.

I used var_dump($this->getURLParams) in my init function to make sure I was getting the right vars coming through, which I am. Once I remove that I am still getting just the default page.ss instead of mypage.ss. Not only that but as I go mypage/1/2 its fine as soon as I get to mypage/1/2/3 I get a 404.