Showing posts with label joomla component. Show all posts
Showing posts with label joomla component. Show all posts

Saturday, 21 November 2015

Joomla database escape() and quote() functions

The escape() function is used to escape bad characters in order to protect against SQL injection.

The quote() function is used to quote strings, because different database dialects have different quoting characters.
So depending on the database system you use, Joomla will choose the appropriate quoting characters.

Friday, 20 November 2015

To add a filter to Joomla component side bar using options

To add a filter to Joomla component side bar  using options

$db   = JFactory::getDbo();
$query = 'SELECT mycolumn FROM MyTable';
$db->setQuery($query);
$rows = $db->loadObjectList();
$options = array();
foreach ($rows as $row) {
   $options[] = JHtml::_('select.option', "$row->mycolumn", JText::_($row->mycolumn));

}
JHtmlSidebar::addFilter('- Select mycolumn -','mycolumn', JHtml::_('select.options',$options,'value', 'text', $this->state->get('filter.mycolumn'), true));

Monday, 12 October 2015

Saturday, 10 October 2015

Reuse / Load a Model Anywhere in Joomla 2.5/3.x

Sometimes you may wish to reuse a certain function that resides in a model outside of your current scope. This helps you save time and reduce duplication. This can be achieved easily by adding the following codes.

Assuming you are trying to call a model "Categories" (/components/com_mycomponent/models/categories.php) belonging to com_mycomponent (this can be called from either within or outside of the com_mycomponent):

jimport('joomla.application.component.model');
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_mycomponent/models');
$categoriesModel = JModelLegacy::getInstance( 'Categories', 'MyComponentModel' );

Now you can call its methods, example:

$categoriesModel->getCategories();

Friday, 9 October 2015

Multiple controllers in Joomla MVC component

Joomla basic tutorial and understand that the main controller is located under components/com_component/controller.php & other file is components/com_helloworld/helloworld.php which is pointing to controller.php file to execute the request. You create new controller folder and put all controllers in that folder


The main controller is typically used to do what you mention in your comment (render a view based on the view parameter, usually specified in the URL). In controller.php, the function that does this is called display(). So the following URL:

http://example.com/index.php?option=com_mycomponent&view=test

Will result in calling the display() function in controller.php and loads the view test in /views/test.

Subcontrollers, in the controllers folder, are generally used for CRUD tasks, but can be called easily by using a task URL parameter. For example:

http://example.com/index.php?option=com_mycomponent&task=test.process

Will result in calling the process() function in /controllers/test.php - notice the task parameter is <controllerName>.<functionName>