开发者

In Joomla, where should I put my classes that calculate?

开发者 https://www.devze.com 2023-01-21 05:18 出处:网络
I\'m working on a joomla component that includes building a schedule. On any given day it needs to look at a set of rule开发者_StackOverflow中文版s (day of the week, date of the year, type of event) a

I'm working on a joomla component that includes building a schedule. On any given day it needs to look at a set of rule开发者_StackOverflow中文版s (day of the week, date of the year, type of event) and return all of the possible start times. It would make sense to have a class that calculates these things, but I'm not sure it fits in the model or controller (and certainly not view) categories. Am I supposed to create a com_myproject/lib (or similar name) and have joomla auto-load the classes?

I'm new to joomla and started with the framework/project provided at http://docs.joomla.org/Building_Joomla_Extensions_with_Apache_Ant.


You should create a helper class. Have a look here for an example, albeit it is for a module, but the same concept applies.


You might want to start off with Developing a Model-View-Controller Component - Part 1 tutorial and work your way through that by hand. Using Apache Ant to learn how write an extension is like taking a canon to shoot fish in the barrel. It can be done but probably not the best way of doing it.

The Joomla! MVC pattern is very peculiar and difficult to understand. I don't quite understand it myself. I was advised on the developer email list to look at how other components are put together. Guess what? All the other developers do it differently, with some of the bigger components looking like spaghetti code in their organization.

The bulk of your component code should be in the controller, either as part of the controller class or a separate class file that's imported in. You don't need a separate library directory unless you're working on a big component with multiple class files. This Joomla! thread might be applicable.

0

精彩评论

暂无评论...
验证码 换一张
取 消