In CodeIgniter, we can extend native libraries by creating our own by creating a file with our subclass prefix and dropping it into application/libraries. Is there any way to do this from within a third_party application? With EE2, expressionengine IS the CodeIgniter application, so I’d be extending and extended library.
Not as automatically as it works in CI.
You can still extend another class in your library, but you can’t alter the library that EE uses at its core. So you need to instantiate your own class. You can still use the loader to do that though:
So to extend form validation you could do:
$this->EE->load->library('form_validation');
$this->EE->load->library('robs_form_validation');And in Robs_form_validation.php in your third_party/libraries folder you would do:
class Robs_form_validation extends EE_Form_validation { ... }Does that help?
From a programming perspective there are ways of doing that, but we recommend against it.
Essentially, if more than one person extends a class we run into conflicts that we can’t resolve. Another add-on or EEs core code may expect a class to work a certain way. It becomes very difficult to troubleshoot. I elaborated on it here here.
Could I ask what you’re trying to do?
OK taking that into consideration, my new plan is to override the class temporarily, do my stuff, and restore the original class, so that no one else is affected.
$this->channel_standalone = new Channel_standalone;
$this->channel_standalone->entry_form();
$temp_output = $this->EE->functions->clone_object($this->EE->output);
$this->EE->load->library(
'../third_party/robs_addon/libraries/RA_Output',
array(),
'output'
);
foreach (get_object_vars($temp_output) as $key => $value)
{
$this->EE->output->{$key} = $value;
}
$this->channel_standalone->entry_form();
$this->EE->output = $this->EE->functions->clone_object($temp_output);I’ll admit this is hacky, but as I see it right now this is the only way I can achieve what I want. With this kind of method EE becomes 100x more extendable.
But really, the root of my problem here is that the channel entries api uses show_error. I don’t think an API should have that responsibility of erroring out my application.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.