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

This is going to seem very n00b, but...


Go to End


3 Posts   1033 Views

Avatar
te_chris

Community Member, 24 Posts

4 August 2010 at 11:16pm

Ok, so i'm building a web app using sapphire as the framework and doing it the proper MVC way and basically bypassing the CMS (using my controller to define the pages dynamically a la codeigniter, rails etc.) because it's mainly a UGC site. I have one question though and one thing that despite becoming VERY familiar with the SS documentation I still can't work out the best way to do a simple hyperlink intelligently. like sure i can do href="/mysite/controller/action/ID" but that's not dynamic enough. is there something i've missed that can allow me to create links like rails' link_to? or a page that summarises the various link modes (but isn't cms centric given i'm not really using it at all).

Avatar
Willr

Forum Moderator, 5523 Posts

5 August 2010 at 8:07pm

I still can't work out the best way to do a simple hyperlink intelligently

Well the best way is to first define a Link method on your dataobject. Since then you can use $Link in the template and things like rss, restful will all be able to $Link as per.

but that's not dynamic enough

How dynamic did you need it do be? Normally on your dataobject you have a specific controller tied to displaying it. By default you can follow the convention of using a argument to determine the action. For example often you will see this on dataobjects.

function Link($action = "show") {
return "controller/$action/". $this->ID. ";
}

So then using $Link(edit) and $Link(delete) works nicely. If you need controller to be an actual page object (with a 'nice' url) you could also do a lookup for that rather than hardcoding controller.

Avatar
te_chris

Community Member, 24 Posts

10 August 2010 at 7:08pm

Edited: 10/08/2010 7:08pm

Ah of course, thanks so much for that! makes perfrect sense.

One more question that I had neglected to consider before:

I've currently got my app setup in the usual way with the theme having a default page.ss template file which is extended by layout and includes. the problem now of course is that all my controllers don't extend Page. What is the best way to structure a template in this instance? WIll layout still apply? Will page still be the default base template which everything else extends from like when I call renderWith->(some form of template in layout) work by parsing page, then any includes, then the requested layout template, or is that only for the CMS? I've been trying to find where the layout method is defined, but i'm probably too tired to work it out properly!