Saturday, 31 August 2013

Joomla1.5 naming conventions, ajax, editor, datepicker, getVar, setVar, ajax, paging

Joomla naming conventions

Joomla is an award-winning content management system (CMS), which enables you to build Web sites and powerful online applications. Many aspects, including its ease-of-use and extensibility, have made Joomla the most popular Web site software available. Best of all, Joomla is an open source solution that is freely available to everyone.

Joomla naming conventions, ajax, editor, datepicker, getVar, setVar, ajax, paging

List of topics which we will cover here
1) How to use ajax with Mootools.
2) How to use Calender in joomla
3) How to use Editor in joomla
4) Comman syntax which we will need.
5) Open lightbox in div/frame in joomla.
6) How to include js/css in joomla in header.
7) How to send email in joomla.
8) How to avoid confliction of mootools with jquery

1) How to use ajax in joomla
<?php JHTML::_('behavior.mootools'); ?> 
<script type="text/javascript"> 
function save_wedpro(id){ 
/*link of URL which will perform action*/
$link = 'index.php?option=com_search&task=save_wedpro&tmpl=ajax&id='+id; 
/*$('updateid') This is div which we need to update*/ 
var myXHR = new Ajax(link, {update:$('updateid')}); 

<div id="updateid"></div> 
<a href="javascript:void(0)" onClick="save_wedpro(100)">Update</a> 

2)How to use Calender following function will load automatically all the files/function which is required for calender following will create a calender
echo JHTML::_('calendar',$row->rota_date, 'name', 'id',$format = '%d-%m-%Y',array('class'=>'inputbox', 'size'=>'25', 'maxlength'=>'19')); ?>

3) How to use editor following function will load automatically all the files/function which is required for editor
<?php echo editorArea( 'editor1', stripslashes($this->row->description) , 'description', '100%;', '600', '60', '50' ) ; ?> 
You can also editor in other way It may be useful when you don't want to display the pagebreak,image,Readmore link below the editor By defaul it display all three button but if you dont't want then just declar in array array('image') means 'image' link will not be displayed
$editor = & JFactory::getEditor(); 
echo $editor->display( 'description', stripslashes($this->row->description) , '100%;', '550', '75', '20', array('image') ) ; ?>

4) Comman syntax for get the value 4 parameter */ 1 para=name of filed 2 para=default value means id not found (optional) 3 para=how will get the value get/post (optional) 4 para=type of field int,string (optional)
<?php $id = JRequest::getVar('id', 0, 'get', 'int',); ?>
for set the value of variable and you can also set the view,layout in view.html.php or in controller
JRequest::setVar('view', 'parties'); 
JRequest::setVar('layout', 'default');  ?>

how to make object of model

<?php $model =& $this->getModel(); ?>

get the login user details

<?php $my =& JFactory::getUser(); ?>

make the database object

<?php $db =& JFactory::getDBO(); ?>

instead of creating object of $my,$db you can user below also

<?php global $my,$database; ?>

//get the layout of view

$layout = $this->getLayout();
//to add the validation automatically on everypage you just need to declear below ths in view.html.php or tmpl file
Apply class 'class="required"' to text box and 'form-validate' to the form as below
<form class="form-validate"> 
<input type="text" name="business_name" id="first_name" value="" class="inputbox required" maxlength="50" /> 

5) Lightbox in Div/Frame You can use lightbox on click event also you can set its demensions i.e. height,width you can view any url in lightbox
<?php JHTML::_( 'behavior.modal' ); ?> 
window.addEvent('domready', function() { 
//below line is very imp for open lightbox 
window.addEvent('load', function(){ 

lightbox in frame

<a class='modal' rel='{handler: "iframe", size: {x: 800, y: 410}}' id='modalWindowLink' href='index.php?option=com_guests&task=editparty&tmpl=component&id='>Open lightbox in frame</a>
no frame just div only
<a class='modal' id='modalWindowLink' href='index.php?option=com_guests&task=editparty&tmpl=component&id='>lightbox</a>
As i have passed "tmpl=component" in url this means that it will load only content section neither header,footer,left, right

6) How to include js/css in header from template We can control the header from tmpl file or view.html.php This will include itself files in html header
$document = &JFactory::getDocument();
//add js/css
$document->addScript( '/media/system/js/sample.js' ); 
$document->addStyleSheet ('/media/system/css/new_style.css'); 
//add meta tags 
$document->setMetadata( 'keywords', $metaKeys );?>

7) Send email
/* Last parameter has 1 means mail will send "html email" use 0 for "text email" */

JUtility::sendMail($mailfrom, $fromname, $email, $subject, $message,1); 

8) Conflict jquery with mootools Joomla by default use mootools but if any reason you need to use jquery alongwith mootools Then jquery will conflict with mootools because both use "$". to avoid this problem you should me make new new object of jquery by declaring below line
<script type="text/javascript"> 
jq = jQuery.noConflict(); 
Now you should use jq instead of "$" for jquery;

9) How to set the joomla errros Message
//if area is empty then give a error msg in red color 
JError::raiseWarning('', JText::_( 'Please select atleast one service Area')); 
//url to which u want to send 
1) Ajax with Mootools 
2) Ajax with Prototype(JQuery) 
3) Access Configuration file
4) Paging in 1.5

<?php 1)
window.addEvent('domready', function() { 
/* ajax alert */ 
$('ajax-alert').addEvent('click', function(event) { 
//prevent the page from changing 
//make the ajax call 
var req = new Request({ 
method: 'get', 
url: $('ajax-alert').get('href'), 
data: { 'do' : '1' }, 
onRequest: function() { alert('Request made. Please wait...'); }, 
 onComplete: function(response) { alert('Response: ' + response); } 
/* ajax replace element text */
 $('ajax-replace').addEvent('click', function(event) { 
//prevent the page from changing 
//make the ajax call, replace text 
var req = new Request.HTML({ 
method: 'get', 
url: $('ajax-replace').get('href'), 
data: { 'do' : '1' }, 
onRequest: function() { alert('Request made. Please wait...'); }, 
update: $('message-here'), 
onComplete: function(response) { alert('Request completed successfully.'); $('message-here').setStyle('background','#fffea1'); 

2)Call an ajax and update div

<script type="text/javascript" src="/templates/system/js/prototype.js"></script><?php 
link = '<?php echo JRoute::_('index.php?option=com_guests&task=deleteparty&tmpl=ajax&id='); ?>' + id;

if(confirm('Are you sure to delete this task?')){ 
new Ajax.Updater('updatedID',link);
3)create object of config

$obj=new JConfig(); 

4) Paging in Joomla

$total = $db->getNumRows(); 
$pagination = new JPagination( $total, $limitstart, $limit ); 
$db->setQuery( $query, $pagination->limitstart, $pagination->limit ); 
$results = $db->loadObjectList(); 
echo $this->pagination->getPagesLinks(); 

Joomla is designed to be easy to install and set up even if you're not an advanced user. Many Web hosting services offer a single-click install, getting your new site up and running in just a few minutes.

Since Joomla is so easy to use, as a Web designer or developer, you can quickly build sites for your clients. Then, with a minimal amount of instruction, you can empower your clients to easily manage their own sites themselves.