2

So, for example, I have 3 classes: Division, Employee, Task. Every task has an employee assigned to it and every employee belongs to a division. Currently I need 4 views:

  • a list of tasks assigned to a selected employee,
  • a list of employees working on a selected task,
  • a list of tasks an employee from a selected divison has worked on,
  • a main list that will show a list of task with an amount of employees it was assigned to.

Outside of joomla if I need to get, for example, a list of tasks assigned to an employee, I just do something like:

$employee = new employee($id_of_employee);
$tasks = $employee->get_tasks();

So what is the best way to integrate it with joomla? Can I include my classes in a component or I'll have to redevelop it?

4

Yes, You can simply include and instantiate your classes and interact with them the standalone PHP way you are used to - yes that is not a problem and Joomla doesn't restrict your ability to that - this approach gives you less to rewrite of your original code.

However if you were up for a challenge, you could refactor your code classes - which are actually models, and create a Model that extends JModelItem from them that Joomla could consume in its views.

Full Official Documentation on creating a Joomla 3.x Extension is available for this.

  • Ok... So, if my class extends another one, can a model extend another model? And can I call another model from a model? – Arter Cadelanne Dec 5 '15 at 18:10
  • 2
    yes yes and yes. Basic PHP 101 :) – Phil Taylor Dec 5 '15 at 20:25
1

Try following code -

require_once(JPATH_SITE_COMPONENT.'/helpers/your.class.php');
YOURCLASS::do();

or

$instance = new Yourclass();
$instance->do();

You can also use a static class with inherited methods like:

YOURCLASS::$subclass->do();

You can also inherit or extend Joomla classes (check the documentation) and please use Joomla's native functions for mailing or database management.

If you use php files with Joomla, please put the following line at the top of every file to prevent external access to your scripts:

defined('_JEXEC') or die('Restricted access');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.