41
bumciach
Re: PHP-Debugging without XOOPS
  • 2009/8/12 9:35

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Sorry OT...
It seems to me that xajax has one advantage over the jquery. Using the XoopsDB or XoopsForm objects with xajax functions is more natural and easy. Am I wrong?

42
kaotik
Re: PHP-Debugging without XOOPS
  • 2009/8/12 12:19

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


Let's analise the diference, I'm not going to do the necessary "include files" since xajax and jquery only need 1/2:
Load a php function into a div with xajax:
PHP INITIAL ROUTINE
$xajax = new xajax();
$xajax->registerFunction("processFormData");
//$xajax->setFlag("debug", true);
$xajax->processRequest();

$Xjavapath=XOOPS_URL.'/modules/tutorial/class/xajax';
$xajaxjava=$xajax->getJavascript($Xjavapath);
$xoopsTpl->assign('xajaxjava'$xajaxjava);


PHP FUNCTION
function processFormData($arg)
{
$newContent "Value of field: ".$arg['myfield'];
$objResponse = new xajaxResponse();
$objResponse->assign("thisID","innerHTML"$newContent);
return 
$objResponse;
}


HTML PART
<{$xajaxjava}>
<
div id="thisID"></div>



Now with ajaxify:
HTML PART
<class="ajaxify" href="phpfunc.php?tst=123" target"#container">The easy way</a>


PHP FILE WITH PHP FUNCTION
function ajaxy($arg)
{
$Hello="welcome to my world at $arg";
return 
$Hello;
}

$tst=ajaxy($_POST['tst']);
echo 
$tst;


Now the xajax part has incomplete code since I'm missing a function to trigger on mouse click, while the ajaxify code has this. While I like to use this jquery plugin, You could just as easily have done this with jquery alone (without plugins).
Initially, I was a little hesitant from switching away from xajax; First because I wasn't familiar with javascript and was a little fearfull of jumping into another language, god knows how much learning it's taken to understand PHP. Second, why leave xajax if I'm profiecient at it? For the first reason, javascript really isn't that hard to learn if you already understand PHP. The basics are quite similar. The second part has a 2 part answer:
1- Simplicity! With xajax you are required to create a xajax function that serves as an conection between javascript and PHP ($xajax->registerFunction). Now when designing with xajax, all calls HAVE to go back to the server. So you are not really taking advantage of javascript wich is a client based language. For instance, you have a table of data and you want to sort by column's. Using old Xoops, you would create an image link that would do a new DB query and reload the whole page. With Xajax, you still do the DB query but only reload the table. With Javascript, once the table is loaded on the client he can sort it as he pleases without any further DB queries! This is great because it's less load on the server. So now you can benefit from javascript, and when necessary do ajax calls to get PHP code.
2- Less code/ faster development. Since I've switched (after an initial learning curve about the basics of javascript) I've been coding with ajax much quicker and taking advantage of an incredible library of plugins available to jquery! Just look at (http://jqueryui.com/demos/draggable/) to see some standard plugins/effects that come with Jquery. Also, since it's a framework, you can easily add more and more plugins to your page. Of course it's not perfect. There are some issues you do run into. However you can use firebug.js and frankblack's great module to troubleshoot any problem either in php or javascript.

I'm going to post a list of useful jquery plugins if people are interested. I've already written a jquery tutorial that's available on my site on how to create XOOPS admin menus. I'm thinking of creating a new one that's more of a beginners guide to javascript.

43
frankblack
Re: PHP-Debugging without XOOPS
  • 2009/8/12 15:58

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


It appears to me, that ajaxify is far slower than xajax on the ajaxify demo site?!? AND if you want to process form data even the ajaxify code is a bit longer (can be seen in the demo). But you are right, xajax has some ugly drawbacks (unless someone has a solution to implement xajax as framework code so that it can be used anywhere anytime), so I will try ajaxify for a few functions, but I ask you to give me a helping hand. Will you?

I take just a basic example. What the script has to to do is select a radio station and shows the players that can be used with that radio station.

PHP function:
function xajaxradio($arg) {
        global 
$xoopsDB;

    
$radioselect $arg['radioselect'];

    
$result1 $xoopsDB->query("SELECT radio_id, radio_stream, canplay FROM ".$xoopsDB->prefix('debaserradio')." WHERE radio_id = ".intval($radioselect)."");
    list(
$radio_id$radio_stream$canplay) = $xoopsDB->fetchRow($result1);
    
$canplayarray explode(' '$canplay);

    
$result2 $xoopsDB->query("SELECT xpid, name, html_code, playericon FROM ".$xoopsDB->prefix('debaser_player')." WHERE xpid IN (".implode(', 'array_map('intval'$canplayarray)).")");

    
$imagerow '';

        while(
$fetch $xoopsDB->fetchArray($result2)) {
    if (
$fetch['html_code'] == 'external') {
        
$imagerow .= '<a href="'.$radio_stream.'" target="_blank"><img src="'.DEBASER_IMG.'/playericons/'.$fetch['playericon'].'" alt="'.$fetch['name'].'" title="'.$fetch['name'].'" />';
    } else {
    
$imagerow .= '<button type="button" name="button'.$fetch['xpid'].'" id="button'.$fetch['xpid'].'" value="'.$fetch['xpid'].'" onclick="javascript:openWithSelfMain(''.DEBASER_URL.'/radiopopup.php?radio='+document.radiolist.radioselect.options[document.radiolist.radioselect.selectedIndex].value+'&amp;player='.$fetch['xpid'].'','player',10,10)" /><img src="'.DEBASER_IMG.'/playericons/'.$fetch['playericon'].'" width="20" height="20" alt="'.$fetch['name'].'" title="'.$fetch['name'].'" /></button> ';
    }
        }

    
$content $imagerow;
    
$objResponse = new xajaxResponse();
    
$objResponse->assign("radiolistresponse","innerHTML"$content);
    return 
$objResponse;
    }


HTML code:
<{$block.xajax}>
<
form style="margin:0px; padding:2px;" name="radiolist" id="radiolist" method="post" action="radio_block.php">
<
select id="radioselect" name="radioselect" onchange="xajax_xajaxradio(this.options[this.selectedIndex].value)">
<
option>-<{$smarty.const._MB_DEBASERRAD_CHO}>-</option>
<{foreach 
item=radiolist from=$block.radiolist}>    
<{
$radiolist.options}>
<{/foreach}>
</
select>
</
form>
<
div id="radiolistresponse"></div>


I would like to see how this can be done with ajaxify. I just want to emphasize, that I don't want you to code for me, but just give me a little push into the right direction.

HINT HINT

44
bumciach
Re: PHP-Debugging without XOOPS
  • 2009/8/12 16:02

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


So far, I only used xajax. I used it to connect to the database without having to reload the page. Such as modification of data or checking a single value (the download thousands of records from database to browser at a time would be pointless in this case). So I have not felt so much this disadvantages you mentioned.

But I recently started to interest jquery. A few days ago I started to play with module Publisher by Trabis which intrducing Tabs from jQueryUI. It's impressive! I must also be interested ajaxify. Thanks for tips!

And about interesting plugins. As I mentioned herehttps://xoops.org/modules/newbb/viewtopic.php?viewmode=flat&type=&topic_id=68797&forum=10 jqGrid plugin looks great. But I haven't found time to look into a bit more yet.

45
kaotik
Re: PHP-Debugging without XOOPS
  • 2009/8/12 18:48

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


@frankblack:
Here's a simple ajaxify example that will acomplish what you want. I've also included firebug.js so that you can use firefox to debug. I've also commented all the javascript code. There's a bug in there that I haven't identified yet (might be behavioural) where it does the ajax call once when you click and another when you select.
Ajaxify Example

I'm going to prepare another example using only jquery.

46
frankblack
Re: PHP-Debugging without XOOPS
  • 2009/8/12 18:53

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Cool! Thx a million, I'll test an report. If it is really so simple ... then ...

47
kaotik
Re: PHP-Debugging without XOOPS
  • 2009/8/13 10:29

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


I wasn't happy with the ajaxify was behaving so I used another plugin for the same example. This one uses a submit button. You can read about the plugin here:
http://www.malsup.com/jquery/form/

jqueryForm example

48
kaotik
Re: PHP-Debugging without XOOPS
  • 2009/8/13 10:44

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


bumciach: I used to do tables using ajax also, I've since partially abandonded it, Why?
Well javascript is a client language, meaning all manipulation is done on the clients side. I load the necessary info for the table unto the clients computer, then let javascript take over and sort it. This way the client can interact with the info as he/she see's fit, without placing an additional burden on the server.
This is what I'm using: Demo Home page. With this you can load 400/600 (or more) records onto the users computer and this jquery plugin will break the results into pages, perform sorting, allow the user to select how many records to see at once and even search through the records. This is the power of javascript.
I've been reading through jqGrid and it's also a great plugin. It can perform the same way. I'm actually going to do some testing with it

49
kaotik
Re: PHP-Debugging without XOOPS
  • 2009/11/3 13:14

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


version 1.3 doesn't seem to work with XOOPS 2.4.1
It gives a fatal error.

50
Mamba
Re: PHP-Debugging without XOOPS
  • 2011/4/4 7:33

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


I have updated the package to the latest FirePHPCore files, and have written a short tutorial for Debugging XOOPS with FirePHP.

See more in this thread

Feedback and improvement suggestions for the Tutorial are appreciated.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

Login

Who's Online

162 user(s) are online (95 user(s) are browsing Support Forums)


Members: 0


Guests: 162


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits