22 April 2010

Joomla get current language

The following code might be useful to you if you want to get the current language in your custom component/module/plugin.

It will get the current language that is active on the website:

$lang =& JFactory::getLanguage();
echo "The current language is:". $lang->getName();

Reference : JFactory/getLanguage - Joomla! Documentation

If you are learning to develop your own Joomla component, module or plugin, the following book is a must have.

You can get it for cheap on Amazon.

11 April 2010

Adding additional Joomla registration fields

The default Joomla registration page is very basic. In many situations, one might want to add field to it. This is how to do it:

Just add the fields you want to the following files:

For saving the info
libraries/joomla/database/table/user.php

Display on registration page
components/com_user/views/register/tmpl/default.php 

For updating info
components/com_user/views/user/tmpl/form.php

Backend user form
administrator/components/com_users/views/user/tmpl/form.php
Joomla! Bible

Replacing MySQL characters

The following MySQL query will replace all occurences of Ã§ in the column 'name' of the 'customers' table with ç

UPDATE customers SET name = replace(name,'ç','ç');

I found it useful especially after copying databases. Copying databases with different collations tend to screw up the characters (especially when working with French accents). So applying this query will fix things up.

This is also useful in many other situations where we will want to replace a character in the database. I leave it to you to think it out.

Update mySQL table with values from another table

Suppose we have two tables myCustomers and allCustomers. We can update the value of table myCustomers based on the value that is common to both tables.

Example

UPDATE myCustomers , allCustomers
SET myCustomers.name = allCustomers.name
WHERE myCustomers.email = allCustomers.email;

What we did here is update all the names of table 'myCustomers' with the names of table 'allCustomers' where their email matches.

Table 'myCustomers' can be a smaller table that stores a small amount of info and table 'allCustomers' can be a reference master table.

French unreadable characters

To fix the problem of unreadable french characters when pulling info from a MySQL database, do this:

$query = mysql_query("SET NAMES UTF8",$conn) or die(mysql_error());

That is, we change the collation of the names column to utf8.