I
I
Igor Pushkarsky2014-01-07 07:21:54
PHP
Igor Pushkarsky, 2014-01-07 07:21:54

How to include Joomla 3 classes in modules and components?

Greetings!
Do not judge strictly, the second day I write in php and even a module for Joomla 3.2.
The essence of the question is this: the module represents a small outline of the form, when changing the fields of which ajax sends a request to the php script, which must take the fields from the database and check the compliance of these fields.
The class itself for accessing the database and getting a list of objects is located in another file (controler.php).
In the case of the main file of the mod_calctrans module, it is possible to connect the file without problems and the method works

include_once JPATH_ROOT.'/modules/mod_calctrans/controller.php';

but in the case of a script that processes an Ajax request, I get an error:
Warning: include_once(JPATH_ROOT/modules/mod_calctrans/controller.php) [function.include-once]: failed to open stream: No such file or directory in V:\home\dev.local\www\modules\mod_calctrans\ajax. php on line 5
Warning: include_once() [function.include]: Failed opening 'JPATH_ROOT/modules/mod_calctrans/controller.php' for inclusion (include_path='.;C:\php\pear') in V:\home\ dev.local\www\modules\mod_calctrans\ajax.php on line 5
sajbjdsadjbdjasjsdj

Why is this happening, how to solve this problem?
Even when returning a response, I get a set of characters, both files are encoded in UTF-8, how to get Russian text from a request processed by Ajax?
Link to my module!
PS: If anyone has literature or links to literature on how to use Freamwork Joomla then share it, preferably in Russian. Much is not clear on docs.joomla.org.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Bakin, 2014-02-08
@recomp

I advise you to read first: joomla-book.ru/development/creating-modules/module...

K
Konstantin, 2014-01-07
@puchkovk

It also writes in English letters on the screen that PHP does not find the file JPATH_ROOT/modules/mod_calctrans/controller.php
Judging by the construction "define('_JEXEC', 1) or die('...');" in line 3 of ajax.php you are calling it directly from the browser. This means that JPATH_ROOT is not defined.
Read about Joomla's inner workings. Unfortunately, I can not advise literature, because. I haven't dealt with this CMS for a long time.

P
prkparadox, 2014-09-12
@prkparadox

you can't just take and make a direct request to the file .../modules/mod_calctrans/ajax.php
when I need to make an AJAX request, I usually do this: I create a component for joomla, I create an AJAX request handler in it. I address something like this: index.php?option=com_component&task=task&tmpl=component&no_html=1&"+Math.random(). Thus I get the answer without extra code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question