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.

General Questions

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

Categorising


Reply

4 Posts   792 Views

Avatar
Harley

10 August 2009 at 1:14am Community Member, 153 Posts

Is it possible for me to categorize sub pages within the cms?

To make things more specific, I have a client page I'm working on. Now these clients have to be categorized so I will have <b>Clients > Client category > Client</b>. This is pretty simple so far and works great but here is where it gets tricky. On my homepage I have a featured client which is randomized. This works great except, as you can see I have created a page for each client category, and because this is a child of 'Clients' it also shows up in the results.

My question really is this:

a. Can I somehow make each client category page unique so I can exclude this from my results in the sql?

b. Is there another approach for categorizing content that I may not be aware of?

Regards

Avatar
Juanitou

10 August 2009 at 6:57am (Last edited: 10 August 2009 6:58am), Community Member, 323 Posts

Hi Harley,

I think you need to delve into complex relationships between data objects ([url=http://doc.silverstripe.org/doku.php?id=tutorial:5-dataobject-relationship-management&s=tutorial]5th tutorial[/url]).

If you create 1-to-many or many-to-many relationship between categories and clients, you could build a simpler to maintain web structure where, for example, you could create unique pages for every client where their categorie(s) data could be shown and a categories holder page with Category children displaying automatically corresponding clients, without requiring the creation of a Client subpage for every Category.

Sorry about my English,
Juan

Avatar
Hamish

10 August 2009 at 10:04am Community Member, 712 Posts

You could just create a simple 'ClientPage' class, and use that:

class ClientPage extends Page {
   
   static $db = array();

}

class ClientPage_Controller extends Page_Controller {

}

Now, in your page class you can do:

// not particularly efficient method to select a ClientPage at random:
function RandomClient() {
   $clients = DataObject::get('ClientPage');
   return $clients->getOffset(rand(1, $clients->Count()));
}

Since 'ClientPage' behaves in the same way as a 'Page', you can add them where ever you like and the RandomClient method will pick it up.

Avatar
Harley

10 August 2009 at 11:16pm Community Member, 153 Posts

Thanks for your feedback Juanitou,

The thing is, I need a seperate page for each client, each client will also have access to this page so they can themselves edit it. It's almost like a profile.

Would it be possible to have a client holder, and then a category holder, then client page? Essentially two holders, one inside the other and then the client page?

If I could somehow make the category page unique then that would be easier for me to manipulate.

As I say it works great for me at the moment, but it is just the part on the homepage which has a featured client, by default it includes the category page as well which I don't want to happen.

Regards