Match *_content "alias" (id-XXX)

For Joomla! 3.x Coding related discussions, please use:

Moderator: ooffick

Forum rules
Please use the mailing list here: rather than this forum.
Post Reply
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Apr 25, 2018 1:27 pm

Match *_content "alias" (id-XXX)

Post by Froman » Wed Apr 25, 2018 2:32 pm


I've built a very simple Module that connects to an external database.

The function is to match a column in the external database with the alias(column) in *_content.
Everything works when I use id from *_content, however that will not scale for my project.

Code: Select all

	$db = JDatabaseDriver::getInstance( $option );

             // Retreive the Data					         
                $value = JFactory::getApplication()->input->get('ALIAS'); <-- I need the alias here instead of id.
                $query = $db->getQuery(true)
                            ->where($db->quoteName('FIELD FROM TABLE')."=".$db->quote($value));
             // Prepare the Query
             // Load the Row
                $result = $db->loadAssoc();
             // Return the Data
                return $result;

Code: Select all

URL: index.php/Categories/Sub-Categories/id-XXX
How do I isolate the XXX part of the url in Joomla?

User avatar
Joomla! Exemplar
Joomla! Exemplar
Posts: 9931
Joined: Thu Feb 15, 2007 5:48 am
Location: Oxford, UK

Re: Match *_content "alias" (id-XXX)

Post by toivo » Sun Apr 29, 2018 5:02 pm

The last part of the URL is usually the alias column from the menu item. If you need the alias from the content table instead, analyse the column 'link' of the menu entry, containing the non-SEF link, and extract the article id, then look up the article from #__content and retrieve the alias column.

Code: Select all

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Log\Log;
$app	= Factory::getApplication();
$db	= Factory::getDbo();
// menu item
$alias   = $app->getMenu()->getActive()->alias;
$msg 	= 'menu alias = ' . $alias;
$app->enqueueMessage($msg, 'info');
// get menu item
$query = $db->getQuery(true)
 			->where($db->quoteName('alias') . ' = ' . $db->quote($alias));	
$result = $db->loadAssoc();
$title	= $result['title'];
$msg	= 'title from #__menu = ' . $title;
$app->enqueueMessage($msg, 'info');
// in case URL is needed
$url	= Uri::getInstance()->toString();
$msg	= 'URL = ' . $url;
$app->enqueueMessage($msg, 'info');
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles

Post Reply

Return to “Joomla! 3.x Coding”