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
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/
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.
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.
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.