1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » custom BlogTree.php etc...
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 747 Views |
-
custom BlogTree.php etc...

4 September 2010 at 3:06am
Hi,
Blog 0.4.0 with SS 2.4
I have the blog folder installed at the correct place and I have my theme and theme_blog located in the themes folder. I also have my 'site' folder at the same level as 'blog' and 'themes'.
I'd like to make modifications to the php files that are located in blog/code.
I've tried copying the blog/code folder to
themes/theme_blog/code
themes/theme/code
site/codeThe files are not being picked up from any location except blog/code.
I don't like having my modified versions of BlogTree.php, BlogHolder.php and so on, including some of the widgets (e.g. TagCloudWidget.php) being in the root blog folder because of the problems this will create at time of upgrading the blog. There must be a way of having local to the theme or site folder, but I've not found a solution that works... I could just be getting in a mess.
Where should I place local versions of files currently in blog/code?
Thanks in advance
Rob
-
Re: custom BlogTree.php etc...

4 September 2010 at 8:02pm
You can't override code as simple as you do with themes. In PHP you can only have 1 name per class. If you want to make modifications to the blog you either need to subclass it or use decorators to hook into any extend() calls the module makes. If you're making extensive changes subclassing the blog classes you need would be the best way.
http://doc.silverstripe.org/dataobjectdecorator
Subclassing is as easy as making your own file say CustomBlogTree.php with
<?php
class CustomBlogTree extends BlogTree {
}
class CustomBlogTree_Controller extends BlogTree_Controller {
}
?>And using CustomBlogTree pages in your CMS rather than BlogTree. You can even 'hide' the original BlogTree as an option in the create menu by using a static http://api.silverstripe.org/2.4/cms/SiteTree.html#var$hide_ancestor
-
Re: custom BlogTree.php etc...

4 September 2010 at 9:44pm
Hi,
Thanks for the guidance... I should of realised, but grew up coding before OOP, which remains utterly foreign to me most of the time...
You said:
>Subclassing is as easy as making your own file say CustomBlogTree.php with
>
><?php
>
>class CustomBlogTree extends BlogTree {
<
>}
>
>class CustomBlogTree_Controller extends BlogTree_Controller {
>
>}
>?>Where would I put tat file... inside mysite/code is my immediate instinct, or does there need to be a blog folder created under mysite?
Thanks again
Rob
-
Re: custom BlogTree.php etc...

4 September 2010 at 10:40pm
Mysite/code is the correct location for it.
| 747 Views | ||
|
Page:
1
|
Go to Top |


