Posted by: twmeier
on Jun 30, 2009
Sometimes it may be hard to know how to best use Joomla's database class. Here are just a few of the most used database functions.
In Joomla 1.5, include the following line of code inside your php:
<?php
$database =& JFactory::getDBO();
?>
Use the $loadObject function when you want to retrieve one row from the database. For example:
$database->setQuery("SELECT * FROM jos_comprofiler WHERE id=125");
$userDetails = $database->loadObject();
You can now access the values as follows:
$userDetails->firstname
$userDetails->lastname
.....
If you want to retrieve more than one row from the database, use the loabObjectList() function. For example:
$database->setQuery("SELECT * FROM jos_comprofiler WHERE id<125");
$userDetails = $database->loadObjectList();
You will now have an array of objects. You can access the values as follows:
$userDetails[0]->firstname
$userDetails[0]->lastname
$userDetails[1]->firstname
$userDetails[1]->lastname
.....
If you want to retrieve a single value from the database, use the loadResult() function. For example:
$database->setQuery("SELECT COUNT(*) FROM jos_comprofiler");
$count= $database->loadResult();
You now have a regular php variable. In this case $count.
There are other Joomla database functions, but these three are the most common.
Posted by: gbluma
on Jun 10, 2009
Every now and then I find myself needing to export a set of objects to XML. I usually find a quick way to write a dumb function to do it, but this is usually not the most elegant solution and rarely does it scale up to handle more complex data structures. The other option is to serialize the data into xml, but usually these methods suffer from a large performance overhead and should only be used if you can tweak the serializer to work only the right pieces of data.
I have since added XMLWriter to my toolset. Which, oddly enough, is built right into PHP (as of version 5.1.2) and based on the widely popular libxml engine. I find it to be very quick, both in performance and in ease of programming. Best of all, the code makes more sense than any of any of my own homemade tools.
Here's an example where demonstrate how to export a list of products to xml:
Posted by: jstartup
on Mar 31, 2009
In the module's xml file add a section for parameters.
<params></params>
Input
<param name="sample_input" type="input" default="default value"
label="Sample Input" description="Mouseover popup description." />
Posted by: gbluma
on Mar 25, 2009
Tagged in: Untagged
I've noticed that in VirtueMart (only on some server setups, mind you) the dialog that pops up when you "Add to Cart" is missing it's message (as follows):
instead of:
I've been struggling with this bug in VirtueMart for a few weeks now. It's been particularly difficult to pin-down since it is intermittent and might have something to do with our server implementation. Regardless, the solution I outline here fix the issue and the only downside is that VirtueMart will not be able to log it's errors to file (which you might not need anyway).
Posted by: gbluma
on Mar 24, 2009
Tagged in: Untagged
JCE is a great tool. It works far better than the default tiny_mce that ships with Joomla. Problem is, it still has a few little bugs here and there--and in this case a lack of configurability.
JCE has a default set of file-types is recognizes as usable for inserting, as a link, into content. These include:
html, htm, doc, docx, ppt, rtf, xls, txt, gif, jpeg, jpg, png, pdf, swf, mov, mpeg, mpg, avi, asf, asx, dcr, flv, wmv, wav, mp3
Posted by: gbluma
on Mar 23, 2009
Tagged in: Untagged
This should be a quick one, hopefully. It will require a bit of programming skill as well as some understanding of how Joomla works behind-the-scenes.
Joomla doesn't come with a built-in module for showing a Login/Logout link. I'm sure that someone in the community has made one, but for verbosity I'll explain how to build your own.
First, let's create a link in our template to send people to our login page.
Posted by: gbluma
on Feb 18, 2009
This article will show you how to build a quick plugin to replace some text in an article before it get's displayed to the user.
Intro
Lately I've been writing a number of content plugins for Joomla. They're pretty simple, but basically it allows you to transform the content at a number of points in Joomla's process of editing, saving, and displaying of that content. In theory you could use it to do anything but it's common to replace text and/or add special content into the articles.
I used to frown on these types of plugins because it's better to just get the data right in the first place. But sometimes controlling the input just isn't possible or perhaps you need to keep the article in a certain format but display it in another format.
Posted by: gbluma
on Feb 2, 2009
Joomla has made module development a piece of cake. If you want a section of your module to display a poll or banner it's really easy. Likewise Joomla has made it easy to edit the content in those modules with module parameters.
... But one thing you haven't been able to do is edit those parameters in a WYSIWYG textarea... until now...
Posted by: gbluma
on Jan 20, 2009
The HTTPS Redirect Plugin redirects a visitor to the same page under HTTPS.
When a user requests a url over HTTP (e.g. http://example.com/secure/stuff/ ) Joomla will handle the redirection to the appropriate HTTPS page (e.g. https://example.com/secure/stuff/ )
Posted by: gbluma
on Dec 18, 2008
In my previous article Write an Advanced Joomla 1.5 Authentication Plugin I went over how to integrate Joomla with an alternate login system (i.e. legacy code from a previous project)
This is good, but we don't need to stop here. We can improve the authentication plugin by attaching session data from our legacy system and essentially merge our legacy session with our joomla session.
For example if we have a database table for session data with the following fields: