Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » This is going to seem very n00b, but...

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

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

Page: 1
Go to End
Author Topic: 618 Views
  • te_chris
    Avatar
    Community Member
    24 Posts

    This is going to seem very n00b, but... Link to this post

    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).

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: This is going to seem very n00b, but... Link to this post

    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.

  • te_chris
    Avatar
    Community Member
    24 Posts

    Re: This is going to seem very n00b, but... Link to this post

    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!

    618 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.