Latest Project

cafe rio iphone app

Testimonials

Banner

Blog Tags

Lab Eleven Blogs

Web design & Programming tutorials
Category >> Joomla Programming

Joomla 1.5 Database Functions

Posted by: twmeier

Tagged in: Programming , PHP , Joomla

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.


XMLWriter in PHP

Posted by: gbluma

Tagged in: XML , Programming , PHP

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:


Joomla Module Parameters

Posted by: jstartup

Tagged in: Modules , Joomla

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." />

Missing Dialog Text in VirtueMart 1.1.2

Posted by: gbluma

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):

virtuemart_missing_text

instead of:

virtuemart_with_text

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).


How to view more file-types in JCE 1.5.1

Posted by: gbluma

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


Adding a Login/Logout link in Joomla Template

Posted by: gbluma

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.


Writing a Joomla 1.5 Content Plugin

Posted by: gbluma

Tagged in: Programming , Plugins , PHP , Joomla

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.


Joomla 1.5 Custom Parameter Type (WYSIWYG)

Posted by: gbluma

Tagged in: Programming , Joomla

joomlaJoomla 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...


Joomla HTTPS Redirect Plugin (Beta)

Posted by: gbluma

Tagged in: Programming , Joomla

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/ )


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:


<< Start < Prev 1 2 Next > End >>

Latest Blogs

Will iPhone Apps Run On iPad?
Jan 29th 2010 by: Trevor M.

How to create a marquee text for an iPhone app
Jan 21st 2010 by: Trevor M.

How to Submit Additional Images in Virtuemart
Aug 7th 2009 by: Trevor M.

Using an Image as a Submit Button in HTML
Jul 31st 2009 by: Trevor M.

Joomla 1.5 Custom Breadcrumbs
Jul 9th 2009 by: Garrett Bluma

Read all blogs