Search
Other Sourcerer questions
Forum

sourcerer ans API, error with "use" and getURI()

Jean-Marie GROUD's Avatar Jean-Marie GROUD
English
--------------------------------------------
Hello

I would like to improve with "sourcerer" but I have not been able to find the information on the Internet.
You indicate that you created the following variables:

$app: The Joomla application framework
$document ou $doc : Le document html
$database or $db: The database
$user :The user object containing the details of the guest or current logged in user
$Itemid :Le menu id de la page
$article: The article object (only available when using the code inside articles)

Question 1
Which structure of Joomla API objects exactly do these variables correspond to? I found a Joomla 4 API documentation but it’s quite complex for me.
api.joomla.org/cms-4/namespaces/joomla.html

Question 2
From your variables, how do you use the APIs in this documentation to access objects?
If this is not possible, how do I create an object to access the API?

Question 3
Retrieve the domain name. I found documentation that gives me the following information:

use Joomla\CMS\Uri\Uri;
$uri = Uri::getInstance();
$url = $uri->toString();


The "use" instruction causes an error. Is this normal? What to do to use it or is there another solution to access this library (or another library)?

Question 4
How can I use "sourcerer" to retrieve the domain name of my site? Can I use one of your variables? If so, which one and how?
Otherwise, on one of your old forum posts ( regularlabs.com/forum/sourcerer/49642-in...rrent-uri-won-t-work ), I found this:

$uri = JFactory::getURI();
echo $absolute_url = $uri->toString(array('scheme','host','port','path','query'));


The instruction gives an error: Call to undefined method Joomla CMS Factory::getURI()
Why?

Thank you in advance for your answers.
Jean-Marie

Français
-------------------------------------------------
Bonjour

J'aimerai me perfectionner avec "sourcerer" mais je n'ai pas réussi à trouver les informatons sur Internet.
Tu indiques avoir créé les variables suivantes :

$app : The Joomla application framework
$document or $doc : The html document
$database or $db : The database
$user :The user object containing the details of the guest or current logged in user
$Itemid :The menu id of the page
$article : The article object (only available when using the code inside articles)

Question 1
A quelle structure d'objets API Joomla ces variables correspondent exactement ? J'ai trouvé une documentation API Joomla 4 mais c'est assez complexe pour moi.
api.joomla.org/cms-4/namespaces/joomla.html

Question 2
A partir de tes variables, comment utiliser les API de cette documentation pour accéder aux objets ?
Si ce n'est pas possible, comment créer un objet qui permette d'accéder à l'API ?

Question 3
Récupérer le nom du domaine. J'ai trouvé une documentation qui me donne les informations suivantes :

use Joomla\CMS\Uri\Uri;
$uri = Uri::getInstance();
$url = $uri->toString();


L'instruction "use" provoque une erreur. Est-ce normal ? Que faire pour l'utiliser ou y a t il une autre solution pour accéder à cette librairie (ou à une autre librairie) ?

Question 4
Comment faire avec "sourcerer" pour récupérer le nom de domaine de mon site ? Puis-je utiliser une de tes variables ? Si oui, laquelle et comment ?
Sinon, sur un des anciens post de ton forum ( regularlabs.com/forum/sourcerer/49642-in...rrent-uri-won-t-work ), j'ai trouvé ceci :

$uri = JFactory::getURI();
echo $absolute_url = $uri->toString(array('scheme','host','port','path','query'));


L'instruction donne une erreur : Call to undefined method Joomla\CMS\Factory::getURI()
Pourquoi ?

Merci d'avance pour tes réponses.
Jean-Marie
Peter van Westen's Avatar Peter van Westen ADMIN
1) Pretty much any Joomla (example) code you find that uses those variables, refer to the same main/common Joomla objects.
For Joomla 4:
$app = $mainframe = Joomla\CMS\Factory::getApplication();',
$document = $doc = Joomla\CMS\Factory::getApplication()->getDocument();',
$database = $db = Joomla\CMS\Factory::getDbo();',
$user = Joomla\CMS\Factory::getApplication()->getIdentity() ?: Joomla\CMS\Factory::getUser();',
$Itemid = Joomla\CMS\Factory::getApplication()->input->getInt(\'Itemid\');

2) No idea what you mean.

3+4) Please try the latest development version from:
regularlabs.com/development-releases
You should now be able to place USE statements at the top of your code.

Otherwise you could do:
$uri = \Joomla\CMS\Uri\Uri::getInstance();
$absolute_url = $uri->toString(array('scheme','host','port','path','query'));
echo $absolute_url;
Please post a rating at the Joomla! Extensions Directory
Jean-Marie GROUD's Avatar Jean-Marie GROUD
OK tanks for out responses.
Jean-Marie
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription