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

Categorising


Go to End


4 Posts   1216 Views

Avatar
Harley

Community Member, 165 Posts

10 August 2009 at 1:14am


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

Community Member, 323 Posts

10 August 2009 at 6:57am

Edited: 10/08/2009 6:58am

Hi Harley,

I think you need to delve into complex relationships between data objects (5th tutorial).

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

Community Member, 712 Posts

10 August 2009 at 10:04am

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

Community Member, 165 Posts

10 August 2009 at 11:16pm

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