Overriding core class via a package
Permalink 2 users found helpful
I have a package and I'm trying to override the core TextHelper.
Filesystem:
/packages/my_package/helpers/text.php
In my package's controller.php:
Then, I try to call the new method:
But no dice ("Call to undefined method TextHelper::foo").
I'm unclear how Environment::overrideCoreByPackage should be used. What am I doing wrong?
Filesystem:
/packages/my_package/helpers/text.php
<?php class TextxHelper extends Concrete5_Helper_Text{ public function foo(){ echo 'bar'; } } ?>
In my package's controller.php:
public function on_start(){ Environment::overrideCoreByPackage('helpers/text.php', $this); }
Then, I try to call the new method:
$objTh = Loader::helper('text'); $objTh->foo();
But no dice ("Call to undefined method TextHelper::foo").
I'm unclear how Environment::overrideCoreByPackage should be used. What am I doing wrong?
Thanks for the suggestion, but clearing the cache had no effect :(
Just to clarify... clearing the cache is not the same as turning off the 'Overrides Cache'. As far as I understand, in order for C5 to even bother looking for your override files and functions, you need to turn off the overrides cache. Once you have stopped adding override files, you can turn that part of the cache system back on.
Thanks for the info. I noticed I had kept the cache overrides off the entire time so I can rule that out as a potential cause for this.
Finally figured this out:
E.g. If you want to override the c5 Area model class...
Instantiating the Environment class the traditional way or calling "overrideCoreByPackage" statically was the problem. The "get" method is where the magic happens.
Thanks for the suggestions here (and to the c5 forum folks) for trying to help me out :)
E.g. If you want to override the c5 Area model class...
<?php // In the custom package's controller.php file public function on_start(){ $objEnv = Environment::get(); $objEnv->overrideCoreByPackage('models/area.php', $this); }
Instantiating the Environment class the traditional way or calling "overrideCoreByPackage" statically was the problem. The "get" method is where the magic happens.
Thanks for the suggestions here (and to the c5 forum folks) for trying to help me out :)
I'm trying to do this but with libraries/view.php. I've used this as my example but for some reason it's still not working.
Is it possible to override the core libraries/view.php?
Maybe i'm missing something?
Is it possible to override the core libraries/view.php?
Maybe i'm missing something?
I'm also trying to override helpers/file.php, but it doesn't works. To override models (eg. beebs93's code. thanks!) are works fine. Isn't there any solution to override helpers/libraries?
class MyPackage extends Package { ... public function on_start() { $env = Environment::get(); $env->overrideCoreByPackage('helpers/file.php', $this); } }
For helpers, in the root overrides folder, the helper class name needs to begin class SiteXxxxxYyyyyyHelper {
Thanks John the Fish, I want to override via my package.
But, my package works today! It was maybe a cache problem.
Thanks to folks!
But, my package works today! It was maybe a cache problem.
Thanks to folks!
class MyPackage extends Package { ... public function on_start() { $env = Environment::get(); $env->overrideCoreByPackage('helpers/file.php', $this); } }
class FileHelper extends Concrete5_Helper_File { public function mymethod() { } }
If you have already tried that, sorry, I don't know any more.