We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Extend libraries from third_party folder

Development and Programming

Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

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.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
15 years ago
Pascal Kriete's avatar Pascal Kriete

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?

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

Well, what I was looking for was to alter an existing core/extended class, so that other parts of EE which aren’t under my control would be affected. I can’t have that effect if I just load my own library. I’ll have to come up with another workaround, thanks Pascal.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
15 years ago
Pascal Kriete's avatar Pascal Kriete

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?

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

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);
       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.