How to find your site’s absolute path in Joomla ?

One common issue occurs while you install a module or plugin in Joomla is that you get error message “JFolder::create: Could not create directory”. This occurs because you don’t have write permission on tmp foler. If you have write permission on tmp folder and still you get this error then check path of tmp folder. and set absolute path of tmp folder there.
You can check tmp path from Site >> Global Configuration >> Server options.
If you don’t know what is absolute path of your then write following code in a php file. Continue reading “How to find your site’s absolute path in Joomla ?”

Advertisements

How can check that Joomla component is active or not ?

In Joomla programming sometime you need to check that component is active or not. Because it is good practice to check first the component is active , instead of getting errors in module. JComponentHelper class has a useful function to perform this task. Following example will shows how to check.

if (!JComponentHelper::isEnabled('com_test', true)) {
return JError::raiseError(JText::_('Test Component Error Title'), JText::_('Test Component is not installed on your Joomla site'));
}

The above code will check that the component ‘com_test’ is active , if it returns false then if condition become true and Joomla will return an error message “Test Component is not installed on your Joomla site”.

Load Joomla liabrary files into module/plugin

jimport() is a core function of joomla and used to load joomla library files.

For example : jimport( ‘joomla.plugin.helper’ );

this syntax will load the file “helper.php” from the joomla liabrary path like : your_site\libraries\joomla\plugin
now you can use this library file functions like as follows :
// Import the user plugin group.
JPluginHelper::importPlugin(‘user’);
// Get the dispatcher.
$dispatcher = JDispatcher::getInstance();
// Trigger the form preparation event.
$results = $dispatcher->trigger(‘onContentPrepareForm’, array($form, $data));

How to use Joomla Model function into a module or plugin ?

You can use Joomla model function into a module/plugin or another joomla extension using following code. Following example shows us how to show a joomla article in a custom extension.

jimport('joomla.application.component.model');
JModel::addIncludePath(JPATH_SITE . '/components/com_content/models');
$Model = JModel::getInstance('Article', 'ContentModel');
$articleId = '1'; //We used here '1' article id
$article = $Model->getItem($articleId);
echo $article->introtext;

Output : [ article content will print ]

“Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type.”