How to access joomla controller / model functions from outside?

I have a website created in Joomla and Jomsocial.

I am creating web services / APIs in Joomla to access a mobile application.

The mobile application will have almost the same functionality as the website.

Can I access the functions (tasks) defined inside the controller/model externally in my web services / API? How?

Note. I use phonegap to develop mobile applications.

+4
source share
2 answers

You cannot directly refer to a specific function in a model or view.

But any public methods without parameters in the controller will be called using

 yoursite/index.php?option=com_yourcomponent&task=yourpublicmethod. 

This will call the specified method and display it in the Joomla template with all the relevant modules, etc.

If you want only the output of the main component, add to the call

 &tmpl=component 

which is displayed through the component.php template instead of index.php, usually the first one loads external resources (css and js) and the output of the main component.

If the function returns the code (html xml or json), you can call it with

 &format=raw 

which returns only the bare output of your public method. This can also be achieved at the component level with instruction

 exit; 

at the end of your public method implementation

+2
source

Joomla CMS implements MVC Patter (module-view-controlle) with a slight difference in view. It implements the representation in the form of a model.

In Joomla, everything is a component. Each component can have its own models, views, controllers, db tables, etc.

A simple example of how this works is to create a component that lets you say โ€œhelloworld component,โ€ and this component is located in JROOT / administrator / components / com_helloworld for the component admin panel part and JROOT / components / com_helloworld for the front-end.

There is one com_helloworld.php file in these directories that runs the entire MVC for this request.

Despite the fact that Joomla implements the Front controller template, you can build your component, but it suits you better (with or without a front controller).

When you request http://domainname.com/index.php?option=com_helloworld , the file I called com_helloworld is invoked and everything inside is executed.

For more information, see this helpful article on developing Joomla CMS 2.5 components:

http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Introduction

Hope this helps :)

0
source

All Articles