Beware of MySQL export

When developing Joomla! extension, most of us uses PHPMyAdmin to export database for our component. This is a great tool in PHP-MySQL world, thanks to developers. But today I have found some error using PHPMyAdmin, it is not directly related to PHPMyAdmin. But it is becauase of some statement in SQL exported script. I made SQL installation file using script from PHPMyAdmin, by changing table prefix to #__ as usual. Then I made a xml manifest file and zip package. When I install mycomponent, what happen? My backend Components menu, it was destroyed by my component menu.ย My component Submenu becomes main items in Components menu.ย What is the problem.

I sat down and tried to fix for the problem. Is it a problem of XML tag in manifest file? After verification and try to correct what Iย  think a cause of problem. Nothing better. Then I went down to see what wrong with it in #__components and then I found the problem!! It is becauase my component menu ID is zero. And Joomla! use parent-child to keep track of menu and submenu. If menu item 's parent is zero then that is a first level menu. Normally menu item with ID zeor doesnot exists in the table, but now my component menu does. So all of them become childs of my component menu item. Then I have to resolve the problem by manually insert my component menu item ID (some value that doesnot exists and not zero), then I change parent ID of submenu of my component to the new entered one. Ok, it come back, all menu items display correctly.

Don't be serious if you did not encounter this error before, I have found what is the cause of problem that is one exported statement in PHPMyAdmin that I didnot delete it.


SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

Normally Joomla assign ID to be zero and insert into database, in normal case without this statement, it will change to some auto-increment value. That works fine, but when this statement comes into play, it causes new inserted ID to be zero and this is the cause of problem. So beware of this statement, remove it from your installation script. Unfortunately I didnot capture any image to show you. My environment is Joomla! 1.5.22, PHP 5.2.14 and MySQL 5.0.

How to implement ToolBar in Frontend

If you are familiar with Joomla! backend development, you may found that Toolbar implemented in backend is quite useful. It is easy to code in backend but there is no standard way in frontend. In this article(s) I will provide a solution used in many of my component development, using this way you can use backend style to create toolbar like this:-

<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
require_once(JPATH_COMPONENT.DS.'libraries'.DS.'baseview.class.php');
class JongmanViewReservations extends JBaseView
{
          function display()
         {
               JHTML::_('behavior.modal');
               JToolBarHelper::title('Jongman :: '.JText::_(COM_JONGMAN_MANAGE_RESERVATIONS));
               JToolBarHelper::custom('reservation.view', 'preview' , 'preview', "View" );
               JToolBarHelper::editList('reservation.edit');  
               JToolBarHelper::deleteList('', 'reservation.remove', "Delete");
                $rows = & $this->get("Items");
                $pagination = & $this->get("Pagination");
                $sorting = & $this->get("Sorting");
                $searchword = & $this->get("SearchWord");
                $schedule_id = $this->get("ScheduleId");
                $this->assignRef('rows', $rows);
                $this->assignRef('pagination', $pagination);
                $this->assignRef('sorting', $sorting);
                $this->assignRef('searchword', $searchword);
               $this->assignRef('scheduleid', $schedule_id);
                parent::display();
       }
}

As you can see from line 10 to 13, it has nothing different with those implemented in backend. Two more differences that you can see are line 4 and 5 which includes baseview.class.php and our view extends from JBaseView. As I have seen from backend implementation that toolbar render occurs in template, but in frontend we have no control over template. So my solution is a base view class that render toolbar and call parent::display() in that view.

Read more: How to implement ToolBar in Frontend

Using JPagination together with Grid.Sort in Frontend

If you don't know, you cannot directly use JPagination together with JHTML::_('grid.sort') in your component at frontend. I found this problem when I develop component to be used in Intranet. I want to let administrators of the component perform their functions in frontend. As you know in backend if they are administartor then I cannot limit their access to only one specific component. However I can do this in frontend and only give theme a registered group member.

The problem occurs if users click on the table header to sort using GRID.SORT and then they click on pagination links e.g. START, PREV, NEXT .... The component will let them to the wrong page. For example, first they go to the page with this url

             index.php?option=com_jtimesheet&task=timesheet.getlist&m=my&Itemid=76

Here, I use controller.task in the url and there are many links with different paramerter m=my, m=all, m=approval etc. When a user goes to this page with above url. and clicks pagination link. It works fine as it creates correct link in this case but when the user clicks on grid to sort the url will reduced to index.php?option=com_jtimesheet&Itemid=76. This is action attribute on the form I used. Ok, there is no problem with grid.sort as I provide hidden input field in the form (task and m in this case). But if user click on pagination link it will go to url

 index.php?option=com_jtimesheet&Itemid=76.

Which is not desired result. The problem occurs only in frontend as JPagination creates link like this <a href="/component/jtimesheet/?Itemid=76"...> and you may have seen the problem it constructs wrong url. But at backend JPagination use onclick of anchore instead like thisย ย  <a href="#" onclick="javascript:........">. And it works in backend as all forms we used (if you familiar with it) are name "adminForm". But we don't have to do so in frontend (as in fromtend we want to use ToolBar and Joomla's JavaScript). You can change this to test if it work by changing pagination.php in your current template folder/html. So whatย are the solution?

Read more: Using JPagination together with Grid.Sort in Frontend

Workflow System for Joomla! 1.5

One feature, important feature that Joomla 1.5 missing is Workflow System. I think this is an area Joomla! should fullfill if Joomla! want to beat Drupal. In many of my extensions, workflow is needed and when looking at KnowledgeTree, I think its workflow can be adopt for Joomla! Ok, it can not answer all my needs but it can answer many basic need. KnowledgeTree uses Entiity based Workflow system which is center around entity, here it is a document or in Joomla! that is article. The counterpart of Entity based workflow system is Activity based workflow which is more complex to implement in my opinion. Or may be I have to learn more on them. If you interested in Activity based Workflow, then it is worth looking at RADICORE 's.

Entity based Workflow

Entity based Workflow as its name implied, centers around entity (refer to ER diagram). The the state of this entity is changed through the workflow life cycle. The change from one state to an other is call transistion. And each transition will be protected by transition guards, that is all requirements must be met by all transition before it can move to destination state. The transition guards can be roles, groups orย  others depending all requirements. Normally EBW uses role based in transition guards but in some case I have modified it to support individual based by let user enters that information.

You are here: Home Articles

© Copyright 2007-2012, All Rights Reserved by Joomlant.org. The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Joomlant.org is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.