Micro blog about Answer to the Ultimate Question of Life, the Universe, and Everything.
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. Joomla

Ajax finally.

Details
Written by: Stanko Milosev
Category: Extensions
Published: 19 August 2008
Last Updated: 04 July 2013
Hits: 8309

After reading few books, digging Internet, finally I found way to use mootools Ajax in Joomla!

Point is in format=raw. If you have any component, if you add format=raw in link, for example

index.php?option=com_ajax&Itemid=60&format=raw you will see only result of component, and that what you need for ajax result.

You can use combination of "standard" ajax and Joomla! but in that case you would loose some of functionality of Joomla!, so better way is to use straight Joomla!

Here is my example, which you can download from here:

 

<?php  // no direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
  // add mootools
  JHTML::_('behavior.mootools');
  // Check the task parameter and execute appropriate function
  switch( JRequest::getVar( 'task' ))  {
    case 'result':
      searchResult();
      break;
    default:
      search();
    break;
  }
  function searchResult()
  {
    echo JRequest::getVar( 'name' );
  }
  function search()
  {
    $doc =& JFactory::getDocument();
    ?>
			<form method="post" action="<?php
						echo JRoute::_('index.php?option=com_regdavzav&task=result&format=raw'); ?>
					         " id="form1">  
  		  Ajax test: <input type="text" value="" class="flatinput" size="45" name="name" id="name"/>            
        <input type="submit" name="button132" id="button1" value="Submit"/>
		  </form>    
<div id="update"></div>
<?php
		$js = "window.addEvent('domready', function()
						{
							$('form1').addEvent('submit', function(e)
								{
									// Stop the form from submitting
									new Event(e).stop();
									// Update the page
									this.send({ update: $('update') });
								});
						});";
		$doc->addScriptDeclaration($js);
  }
?>

With JHTML::_('behavior.mootools'); you are including mootools framework in your component. $doc =& JFactory::getDocument(); you will use for adding javascript ($js = ...) And in <div id="update"></div> you are actually updating page with informations from Ajax. <div> must be in function search() otherwise you will have problems (to me happened that I always added result, instead of cleaning previous).

I hope that this is all.

Creating components

Details
Written by: Stanko Milosev
Category: Extensions
Published: 12 August 2008
Last Updated: 13 August 2008
Hits: 12490

In this category I will try to write about creating extensions in Joomla!

 

First, I will start with creating components.

This example, I took from Professional Joomla!, which I simplified, this is not MVC, as much as I think, but it is good as a starting point.

We will create three files: admin.hellopost.php, hellopost.php and hellopost.xml.

hellopost.xml we need for installation and it look like this:

<?xml version="1.0" encoding="utf-8"?>
<install version="1.5.0" type="component">
<name>HelloPost</name>
<author>Stanko Milosev</author>
<version>1.0.0</version>
<description>Hello world, posting from form</description>
<files>
<filename component="com_hellopost">hellopost.php</filename>
</files>
<install>
</install>

<uninstall>
</uninstall>
<administration>
<menu>Hello post</menu>
<files>
<filename component="admin.hellopost">admin.hellopost.php</filename>
</files>
</administration>
</install>

 

 

Now hellopost.php:

 

 <?php
/**
* @version $Id: guestbook.php 5203 2007-06-15 02:45:14Z DanR $
* @copyright Copyright (C) 2007 Dan Rahmel. All rights reserved.
* @package Guestbook
* This component displays guestbook entries and allows the addition
* of entries from registered users.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

// Check the task parameter and execute appropriate function
switch( JRequest::getVar( 'task' )) {
case 'hello':
hello();
break;
default:
displayHello();
break;
}

// Process data received from form.
function hello() {
echo JRequest::getVar( 'hello' );
}

// Output a list of guestbook entries
function displayHello() {
?>

<form action="index.php?option=com_hellopost&task=hello" method="post" id="formica" name="formica">
Say:
<input type="text" size="20" name="hello" value="Hello world"/>
<input type="submit" value="Submit" name="Submit"/>
</form>


<?php
}
?>

 

With JRequest::getVar( 'task' ) we get variables which we posted ($_POST in pure PHP), my problem is that I coudn't do it with get method.

In case that JRequest::getVar( 'task' ) is equal hello (in PHP would be $_POST['task']=='hello'), than we call hello function in other case we call displayHello.

admin.hellopost.php I didn't change, but I think that file could be even empty. Component you can download from here.

A bit more about MVC.

Details
Written by: Stanko Milosev
Category: MVC
Published: 02 December 2008
Last Updated: 19 December 2009
Hits: 5790

It seems that phpeveryday site does not working anymore, but I found on Joomla! site also a tutorial about MVC:

http://forum.joomla.org/viewtopic.php?f=231&t=136576
http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,components:hello_world_mvc1/

Also, I create two components, one where is MVC applied, and second without MVC.

Here is with MVC, and here is without.

If in our XML manifest file, give name of the component  hello, for example, in root folder of component, com_hello, for example, must be hello.php - that's about creating components.

In MVC component which I puted for download, I also explained some of API's of Joomla! framework.

MVC

Details
Written by: Stanko Milosev
Category: MVC
Published: 25 September 2008
Last Updated: 19 December 2009
Hits: 5555

Here I will write about creating components using Model - View - Controler design pattern in Joomla! framework.

Firs of all, what is MVC?

MVC design pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. Taken from Wikipedia.

Second, how we built MVC in Joomla! framework?

I don't know :)  I am still learning it, so here are some informations which I found.

I was using  phpeveryday web site as a base.

If we create hello component, as it is described in phpeveryday web site, we will need following files, and folders:

com_hello - root dir
com_hellocontroller.php - here we are defining our model and view... Still I am not 100% sure what is used for, my guess is that here we will define functions and variables which we will use for view and model.
com_hellohello.php - our base - also not quite sure about it, I think it does redirect and execute a function which will be defined in task variable
com_helloviewsallview.html.php - here we are defining variables for our view
com_helloviewsall mpldefault.php - here is our view
com_hellomodelsall.php - model - here we are accessing to database, for example, and gets data as an array

You can download component, which I will use as a test bed, created by using phpeveryday, from here.

For now, this is all...

  1. Add SyntaxHighlighter to Joomla 4
  2. Anchores
  3. Google maps
  4. Add jQuery in Joomla 3.x article

Subcategories

Extensions

MVC

Joomla

Page 3 of 7

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7