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.

Data Model Questions /

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

Display a DataObject on a new "own" page


Go to End


24 Posts   16452 Views

Avatar
Willr

Forum Moderator, 5523 Posts

31 March 2010 at 1:13pm

@timwjohn - I think it would be able to support more rules, you probably need to define your own rules though.

// in your config
Director::addRules(100, array(
	'$Controller/$Action/$ID/$OtherID/$NextID/$FurtherID/$AnotherID/$YetAnotherID' => '*'
));

Ref: http://doc.silverstripe.org/doku.php?id=director

Avatar
timwjohn

Community Member, 98 Posts

1 April 2010 at 8:10am

Really? Wow, SilverStripe never ceases to impress me. Thanks Willr.

Avatar
LinseyM

Community Member, 99 Posts

18 June 2010 at 9:26am

Hi there,

Had this all working perfectly in 2.3.X using this method: http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page/

But I copied the code into a 2.4 install and I'm having some problems. I am sure I've replicated it over properly.

So on this page I list all of the dataobjects:

http://www.mysite.co.uk/services/self-build-developments/home-types/

And clicking "more info" for any one of the listings appends the URL with the object ID, like so:

http://www.mysite.co.uk/services/self-build-developments/home-types/3

However, instead of displaying the object data, I get page not found instead!

I don't think I've missed anything obvious.

If its any use I could post up the code? Am wondering if its something to do with the URLs in 2.4 but am stuck!

Thanks guys.

Avatar
edk

Community Member, 39 Posts

18 June 2010 at 6:39pm

Uncanny timing...I was working with a DataObject Class that I wanted to use this method as well....

Okay so it totally has to do with 2.4 and nested urls...the issue is two fold (at least the solution that I got to work).

1. In the Page class you now should define allowed actions.

static $allowed_actions = array(
			'actionName'
		);

The catch here is that now your urls will have to have this defined action. You cannot just use the $ID b/c it is dynamic and you won't be able to define all those in the $allowed_actions array.

2. Okay so you will have to tweak you code some to look for your action and the parameter now as well. Here is what I did.

public function  getIndividualDataObject(){
			
			if ($this->request->latestParam('Action')) {
				$parameter = $this->request->latestParam('ID');
				
				if ($parameter) {
					$DataObjectID = Convert::raw2xml($parameter);
					if($DataObjectID){
						$DataObjectInfo = DataObject::get_by_id('DataObjectClassName', $DesignGuideID);
					
						return $DataObjectInfo;
					}
				}
			}
	}

Now lastly you will need to update your links that call your Single DataObjects to include the action that you added to your $allowed_actions. Example.

{$Top.Link}actionName/{$ID}

Hope this helps...

- Ed

Avatar
LinseyM

Community Member, 99 Posts

18 June 2010 at 8:18pm

Thanks Ed! I don't 100% understand this, but i think I get the jist of it! I will have a go at that today.

Fingers Xd.

L

Avatar
Enclave SSC

Community Member, 31 Posts

29 June 2010 at 2:30am

Edited: 29/06/2010 2:53am

Having the same problem here. Linsey, did you get this to work. I tried Eds changes but no joy as yet. Still get a page not found in ss 2.4

Update: I sorted this out by moving allowed_actions onto the controller. Silly me. - Thanks

Avatar
LinseyM

Community Member, 99 Posts

29 June 2010 at 2:40am

can't get it to work - i am getting page not found - or sometimes an error, but thats deffo just because i am footering about with it!

am still trying to puzzle it out - think i'm maybe just missing something obvious,

let me know how you get on.

Linsey

Avatar
Enclave SSC

Community Member, 31 Posts

29 June 2010 at 2:54am

Edited: 29/06/2010 2:54am

Hey Linsey

I got it working. If you still stuck just paste me your code and I will help out.