Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Best method to determine if request is in cms / admin

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: 550 Views
  • brice
    Avatar
    Community Member
    50 Posts

    Best method to determine if request is in cms / admin Link to this post

    I'd like to decorator to augment searchable fields only if the request is within the cms / admin section of the site. So far I do the detection as follows;

    if(substr(Controller::curr()->getRequest()->getURL(), 0, 6) == 'admin/')

    There's a few flaws I see in this;

    1. It is long.
    2. It is hardcoded & I don't account for the admin section changing from 'admin/'. (e.g. it doesn't use a static method to determine the actual base CMS url).

    Is there a better & more recommended method?

    Thanks!

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Best method to determine if request is in cms / admin Link to this post

    I've no idea if it's the recommended way of doing it or not but I use

    if (is_subclass_of(Controller::curr(), "LeftAndMain"))

    This won't break if the URL changes but if the base class changes you're screwed.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Best method to determine if request is in cms / admin Link to this post

    I have decorated the LeftAndMain class to manipulate certain things. I would register if I have passed through there in order to tell if I was in the admin section.

    since you might read this - Brice - I' really appreciate a response on your excellent looking sortweight module - I've been trying to use it on a fresh 2.4.5 install with ModelAdmin - if it is designed for that (or I'm missing something basic) please let me know...
    http://www.silverstripe.org/all-other-modules/show/14921?start=8

    Barry

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