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

How to create reusable components

Development and Programming

mweichert's avatar
mweichert
68 posts
about 17 years ago
mweichert's avatar mweichert

Hello,

I am enjoying my development-time in EE. Modules, plugins, and extensions are fairly easy to develop. I come from a strong OOP background (C++, Java, C#, Python, Ruby), but EE really got me introduced me to PHP. I used Ruby almost exclusively just before trying EE. I must admit, there are things that I miss- such as the rich STDLIB, Meta Programming, and Mixins, but overall I evaluate PHP to be something between Java and Ruby.

Anyhow, I’m not sure how to go about creating reusable components (modules/classes) in EE or in PHP for that matter. For example, I have an extension and a module that need to share an object. What is the best way to go about that? I came across PEAR, which I thought might solve my problems… but I thought I’d post here first to see what others do to solve this problem.

Lastly, I was hoping to get some used practices in separating the presentation logic from the rest of the code in an EE module/plugin/extension. Are there templating engines that can be used somehow?

Look forward to your replies, feedback, and suggestions.

Thanks, Mike

       
mweichert's avatar
mweichert
68 posts
about 17 years ago
mweichert's avatar mweichert

Hi,

I need some help understanding how to create reusable components. I thought I’d post in the community forums as well so that everyone could benefit.

Please see: http://ellislab.com/forums/viewthread/88016/

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
about 17 years ago
Ingmar Greil's avatar Ingmar Greil

I am sorry, is there an underlying technical issue that needs to be resolved?

       
mweichert's avatar
mweichert
68 posts
about 17 years ago
mweichert's avatar mweichert
I’m not sure how to go about creating reusable components (modules/classes) in EE or in PHP for that matter

How do I share objects between multiple modules, extensions, and plugins?

Thanks, Mike

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
about 17 years ago
Lisa Wess's avatar Lisa Wess

Hi, Mike,

I’ve merged your threads; no need to cross-post. Thank you.

       
Justin Hurlburt's avatar
Justin Hurlburt
344 posts
about 17 years ago
Justin Hurlburt's avatar Justin Hurlburt

Greetings Mike,

There are a couple ways you could accomplish this. You could use additional files and include and instantiate common class objects, or, include and instantiate in a constructor as seen in Fresh Variables.

       
mweichert's avatar
mweichert
68 posts
about 17 years ago
mweichert's avatar mweichert
Greetings Mike, There are a couple ways you could accomplish this. You could use additional files and include and instantiate common class objects, or, include and instantiate in a constructor as seen in Fresh Variables.

Could you post an example please how to include additional files? Does PHP have an include path? In Ruby, I would do the following: - Create a gem to package the modules and classes - Install the gem on my computer - In my module, I would then include:

require 'rubygems'
require 'my_gem'

From what I understand, are you suggesting that I do something like this: - Add my shared module to document_root - To each module, include the shared module using something like:

include_once 'my_shared_module'

Is that the best way of accomplishing this? I’m not sure how I’d package the shared module. Ideally, I want it to be easy for users to install my extensions.

       
Justin Hurlburt's avatar
Justin Hurlburt
344 posts
about 17 years ago
Justin Hurlburt's avatar Justin Hurlburt

Will these extensions be for your module, or are they completely separate?

       
mweichert's avatar
mweichert
68 posts
about 17 years ago
mweichert's avatar mweichert
Will these extensions be for your module, or are they completely separate?

The extension won’t be for my module no, but for an EE-bundled module.

Thanks, Mike

       
mweichert's avatar
mweichert
68 posts
about 17 years ago
mweichert's avatar mweichert

Is PEAR the best way of handling this? Oh, and just a very subtle nudge too, in EE 2.0 will I be able to do something like:

$this->library->load('shared_module');
$this->shared_module->my_func();

Ignore the second question if you must.

Thanks, Mike

       
Justin Hurlburt's avatar
Justin Hurlburt
344 posts
about 17 years ago
Justin Hurlburt's avatar Justin Hurlburt

In this instance, since you aren’t creating linked extensions/modules, reusable code isn’t really a viable path. There are so many uncertainties, and hurdles. I’m not saying it can’t be done, I’m saying I wouldn’t recommend it. When an extension and module that are linked use the same code, you can instantiate it in one of the constructors, since yours are separate, this approach wouldn’t work.

Also, if you were to take the route of including the files in a separate shared directory, you would have to maintain updating every extension and module you released for every change you make to the shared object. Further, there would be no way to control which version of the shared object the user has installed The user could download a newer version of an extension, and an older version of a module and be left with incompatibilities with the shared object. PEAR would not be a viable answer as some users and hosting solutions don’t utilize it.

       

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.