Wednesday 26 January 2011

Module to record the username of a user when they access a page?

We've been asked to come up with a module that can be embedded in a page and will insert into a database table the username of the user accessing that page.  I've tried Google searching but can't find anything.

I did find a forum post that talks about doing something similar:
  • Create the table using:
    CREATE TABLE `databasename`.`jos_names` (`id` int(11) NOT NULL auto_increment, `firstname` VARCHAR(100), `lastname` VARCHAR(100), PRIMARY KEY  (`id`) )

  • Then write your module using: $db =& JFactory::getDBO();
    $query = "INSERT INTO `#__names` (`fname`, `lname`)
    VALUES ($fname, $lname);";
    $db->setQuery( $query );
    $db->query();

Thursday 6 January 2011

Load Position

A colleague just showed me something useful.


If you want to load a module within an article:
  • In the module set the position to one that doesn't exist as a position in your template, e.g. InTheMiddleOfMyArticle
  • In the article use the loadposition tag to put it where you want, e.g. {loadposition InTheMiddleOfMyArticle}
  • Check the page with the article and the module should be there.