5102 Posts in 1520 Topics by 1116 members
| Go to End | Next > | |
| Author | Topic: | 4691 Views |
-
Re: Alternative Redirect to First Child use

27 May 2009 at 12:39am
You mean, you put the above pseudo code in the Page class instead of the HTML like I did?
-
Re: Alternative Redirect to First Child use

27 May 2009 at 7:44am
You mean, you put the above pseudo code in the Page class instead of the HTML like I did?
Yes, in a page class.Ben
-
Re: Alternative Redirect to First Child use

22 July 2009 at 9:14pm
Thank you SilverRay! That's a nice idea.
-
Re: Alternative Redirect to First Child use

1 February 2010 at 6:59pm
Hey Ben,
Just coincidentally I stumbled on this thread again and noticed that I never followed up, so here it goes, just in case other users find it:
class Page_Controller extends ContentController {
public function init() {
if($this->RedirectToChildOne) {
if($children = $this->Children()) {
if($firstChild = $children->First()) {
Director::redirect($firstChild->Link());
}
}
}
parent::init();
}
}In this way you can forego the template code. Thanks Ben for reminding me on this method ;)
SR
-
Re: Alternative Redirect to First Child use

1 February 2010 at 8:28pm
Let me suggest an improvement: Override the Link method of your class with a code like this:
function Link() {
if($this->RedirectToChildOne) {
if($this->Children()->First())
return $this->Children()->First()->Link();
}
return parent::Link();
}That way, the page-link will point to the first child if RedirectToChildOne is checked, saving the user (and the webserver) from a lot of redirects.
For first-child redirects, I usually use a specialized page class (http://pastie.org/803850). I don't see the point in having a checkbox, since you could just as well change the page-type in the Behavior tab. This is preferable imho, since it updates the CMS UI accordingly. You no longer have a content field to enter content that will never be shown and you can use another page-icon that helps the user to easily spot these redirector pages.
-
Re: Alternative Redirect to First Child use

1 February 2010 at 8:51pm
Ah, very smart banal, thanks for your suggestion! There can be a lot of redirects indeed when multiple pages in a hierarchy have redirects.
I used to have a separate class for redirects actually, then I thought to bring it to the Page class for universal use, but your approach makes sense. In my case, sometimes a user wants to revert back to the original page without a redirect, that's why I made it a checkbox, the original page with contents is then still there...
Anyway, I should think more of overriding existing methods ;)
SR
-
Re: Alternative Redirect to First Child use

1 May 2010 at 12:30am
@banal: Many thanks for sharing, that was exactly what I was looking for
Saved me a lot if time!
Best Bjoern
| 4691 Views | ||
| Go to Top | Next > |



