Question regarding component structure

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
wanner
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Sat Jan 24, 2009 6:05 pm

Question regarding component structure

Post by wanner » Wed Mar 04, 2009 2:56 am

Hi,

I am developing a component (lets call it com_library) which is supposed to work as a "helper component" to be used with other components. That is it will provide a library of functions that can be called from the other components. And it will contain a backend for some settings.

Before i start developing i would really appreciate if someone could give their thoughts on the structure that I have in mind.

The backend is only supposed to provide an administrator interface to access the database (edit and save different settings) and will strictly follow Joomla! MVC structure.


Now here is the part where im uncertain if im doing it right, where should i place the library file where all the functions are placed (this is the file that other components need to access in order to access the provided functions).

I thought that a decent solution would to simply create a PHP file containing the functions in the frontend of my component (Note that the frontend wont follow MVC at all since there really is no frontend, but it feels wrong to place this library file in the backend).

To clarify:
Lets say the library file is called library.php
then I will place that file in
components/com_library/library.php

If i want to use this library in another component i will enter the row:
require_once(JPATH_SITE.DS.'components'.DS.'com_componentname'.DS.library.php');
in order to be able to access the functions.

Is there anything wrong with this approach? I know that it will work but is there a better approach to take? Would it be better to place the library file in the backend and skip the frontend alltogether (since there really is no frontend)? The reason i thought i would place it in the frontend is that I dont like the thought of frontend components and modules accessing a file in the backend of my component. Or perhaps it would be better to place my file in the joomla_installation/libraries folder?

Is everything in the libraries folder automatically included?

I would really appreciate any thoughts you might have on the subject!

Thank you!

__B__
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Mar 13, 2009 1:34 pm

Re: Question regarding component structure

Post by __B__ » Fri Mar 13, 2009 7:11 pm

This is an interesting subjetc, I've been looking for a solution for this "problem" as well.

Suppose you work at a company, and you develop some software to your clients. You already have some patterns to a lot of stuff that could be at yourcompany.php: Friendly Error Classes, and would like to re-use all that stuff: or you develop a lot of components that share functionality, so you want to develop a base class for these components, using inheritance and excluding ducplicated code.

My doubt is the same as yours: I don't know if, in a future version of Joomla, putting a .php inside a folder in folders that already have a purpose will result in problems.

If an automated script is planned for every file or component in /components/, for example (auto-registering them in database), if I'm putting a custom library there I'll have problems. So, an official way of adding custom libraries is a great idea.

A solution for using custom libraries could be like this: create a field "type" in the database telling that the component you created is a library or a normal component; create another property in the xml, just telling it's a library; or just the joomla "being smart" and identifying that if there's a folder in /components/ and this componente it's not registered in the database and it doesn't have xml or something like that, is a library; solutions are endless.

What are your suggestions?

__B__
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Mar 13, 2009 1:34 pm

Re: Question regarding component structure

Post by __B__ » Mon Mar 16, 2009 2:09 pm

Anyone? There's a way to create a lib and use it in a correct, semantic way or just doing this "hack" of placing it inside a folder that the Joomla Framework sees and do an import statement?

There's a milestone or something like that about this issue so I can read and try to implement it the right way?

Thanks in advance!!!

__B__
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Mar 13, 2009 1:34 pm

Re: Question regarding component structure

Post by __B__ » Thu Mar 19, 2009 3:41 pm

I'll simplify to turn this on in a discussion: How do you use similar objetcs, functions, across components, modules and plugins, without duplicating code? If you have functions.php with a lot of functions that you use a lot, and usually uses in various components like com_mycomponent1 and com_mycomponent2, where do you usually put your functions.php?

Thanks!!!

User avatar
raynor85
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Thu Feb 12, 2009 12:00 pm

Re: Question regarding component structure

Post by raynor85 » Fri Mar 20, 2009 9:05 am

I think there're no standard definition about classes which share code, because joomla Framework allows user to use code from JModel, JView & JController. Maybe this restriction is a precaution preventing custom-not standard architectures. But i have a similar problem too, and no answers in merit means probably the worst effect, because everybody will try doing his custom-not standard architecture. I hope somebody can clear this issue.


Locked

Return to “Joomla! 1.5 Coding”