Loading an User Object with User Name or User ID in Joomla
You can load a specific user object with just the user name or user ID when using the getUser() method.
$user = JFactory::getUser('username');
$user = JFactory::getUser(55);
You can load a specific user object with just the user name or user ID when using the getUser() method.
$user = JFactory::getUser('username');
$user = JFactory::getUser(55);
You can use the JHTML helper library to draw a custom drop down lists.
JHTML::_('select.genericlist', $dataArray, $name, $attributes,
$valueField, $textField, $selectedValue);
The $dataArray must be an associative array like this
$arr[] = Array('val'=>1,'text'=>'Jan');
$arr[] = Array('val'=>2,'text'=>'Feb');
The $name is the name you want to give the drop down list.
The $attributes are the list properties you want to add.
The $valueField is name of the array field used for the actual value of list item.
The $textField is name of the array field used for the list item text to display.
This will display the dropdown named lstMonths with two months from $arr:
echo JHTML::_('select.genericlist', $arr, 'lstMonths', 'onChange=\"changeFunc()\"', 'val', 'text', $_POST['lstMonths']);
The actual select helper file is located in /libraries/joomla/html/html/select.php
You can do http requests using the Curl library and decode the JSON result with json_decode() function. PHP 5.2 and above comes with the JSON library functions.
The following example will send a request to brightcove’s api using curl and extract some video thumbnail image links. The result will be a list of links in json data format.
The json_decode() function will then convert the json object into an associative array and will finally print out the links.
<?php
//check if you have curl loaded
if(!function_exists("curl_init")) die("cURL extension is not installed");
$url = 'http://api.brightcove.com/services/library?command=find_all_videos'.
'&video_fields=thumbnailURL&token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.';
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r=curl_exec($ch);
curl_close($ch);
$arr = json_decode($r,true);
foreach($arr['items'] as $val)
{
echo $val['thumbnailURL'].'<br>';
}
The most common way to produce raw output in Joomla is to pass the format= raw parameter in the url.
Joomla has four supported document type objects: html, pdf, feed and raw. When passing no format parameter the default is html. Html format is just the normal html output. This article covers the use of raw. You use raw to generate content that do not fit within the other document types.
The following method will allow you to set the document format within the component itself. This might be useful if you want to keep your url clean of any query string values.
You cannot simply do a setVar(‘format’,'raw’) in the component. The document type is set before the component is even called. So you have to manipulate the document object itself in order to set the format within the component.
Place the following three lines in the display() function of the controller before the view is displayed.
You first get an instance of the current document object.
$document = &JFactory::getDocument();
Then get instance of the raw document object.
$doc = &JDocument::getInstance('raw');
Replace the current document type with the new one.
$document = $doc;
This has the same effect as passing format=raw in the url.
Now set the mime type of the document. This document will be a rss feed.
$document->setMimeEncoding('application/rss+xml');
So This is what the display() function looks like in your controller file
function display()
{
$document = &JFactory::getDocument();
$doc = &JDocument::getInstance('raw');
$document = $doc;
$document->setMimeEncoding('application/rss+xml');
if ( ! JRequest::getCmd( 'view' ) ) {
JRequest::setVar('view', 'someview' );
}
parent::display();
}
Once you do this the controller will be looking for the view entry file named view.raw.php in the /components/com_somecomponent/views/someview folder. Just copy the view.html.php file and name it view.raw.php
When you want to make a <ul> to list horizontally and to wrap you normally set the style display: inline-block. In IE 7 simply doing this will not make it display correctly. It will just display as one vertical column.
You will need to add the following style attributes that are specific to IE to make the <ul> list horizontally. This will make your <ul> display correctly on every browser. These styles are set in the <li> tags of the <ul>.
<style>
.menu li {
/* All other standard compliant browsers*/
display: inline-block;
/* For IE 7 */
zoom 1;
*display: inline;
}
</style>
Some browsers will not show a table cell border or background if their is no actual content in the cell. You will need to set the following style to display cell formatting no matter if their is content or not.
<style>
.mytable td {
empty-cells:show;
}
</style>
You can render modules within a view layout file.
Rendering a module position
The following will load a module into a layout file. e.g. views/category/tmpl/default.php
It will honor whatever parameters have been set for this module in the backend and whether or not it is activated for the current menu item.
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$position = 'pics';
$options = array('style' => 'raw');
echo $renderer->render($position, $options, null);
Rendering default module with no position
This shows how to render a module directly. If parameters need to be set then need to pass them to the module. The main difference here is that its loading the actual module by module name and the previous example is loading by position. This method has advantage of allowing you to specify whatever parameter is needed by not being dependent what is set in the backend.
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$options = array('style' => 'raw');
$mod = JModuleHelper::getModule('mod_justdoit');
$mod->params = "cols=2\nrows=10";
echo $renderer->render($mod, $options);
This is an alternative way of loading a module directly:
jimport('joomla.application.module.helper');
$mod = JModuleHelper::getModule('mod_justdoit');
$mod->params = "cols=2\nrows=10";
$attribs['style'] = 'raw';
echo JModuleHelper::renderModule($mod, $attribs);
Should not use $module variable when retrieving the module. If this variable name is being used for the global module object then re-assigning it in the view will cause problems.
These applications will allow you to test your site in different versions of IE without the use of resource hogging virtual machines.
The following window application will allow you to test your site in IE 5.5 up to IE 9 preview on Windows 7, Vista and XP
This is an actual Microsoft application for testing IE 6 to 8
Microsoft Expression Web SuperPreview for Windows Internet Explorer
This function will extract a number of words from a string. Uses a regular expression search to get the words.
function get_words($str,$count)
{
return implode(" ", array_slice(preg_split("/\s+/", $str), 0, $count));
}
$string = "In Scott Pilgrim vs. the World, the titular character is definitely experiencing girl problems.";
echo get_words($string,10).'...';
This example will print out the first 10 words: ‘In Scott Pilgrim vs. the World, the titular character is…’