xoops forums

bumciach

Not too shy to talk
Posted on: 2009/8/12 9:35
bumciach
bumciach (Show more)
Not too shy to talk
Posts: 153
Since: 2007/6/25
#41

Re: PHP-Debugging without XOOPS

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?

kaotik

Just can't stay away
Posted on: 2009/8/12 12:19
kaotik
kaotik (Show more)
Just can't stay away
Posts: 861
Since: 2004/2/19
#42

Re: PHP-Debugging without XOOPS

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.

frankblack

Just can't stay away
Posted on: 2009/8/12 15:58
frankblack
frankblack (Show more)
Just can't stay away
Posts: 830
Since: 2005/6/13
#43

Re: PHP-Debugging without XOOPS

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

bumciach

Not too shy to talk
Posted on: 2009/8/12 16:02
bumciach
bumciach (Show more)
Not too shy to talk
Posts: 153
Since: 2007/6/25
#44

Re: PHP-Debugging without XOOPS

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 here https://xoops.org/modules/newbb/viewto ... =&topic_id=68797&forum=10 jqGrid plugin looks great. But I haven't found time to look into a bit more yet.

kaotik

Just can't stay away
Posted on: 2009/8/12 18:48
kaotik
kaotik (Show more)
Just can't stay away
Posts: 861
Since: 2004/2/19
#45

Re: PHP-Debugging without XOOPS

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

frankblack

Just can't stay away
Posted on: 2009/8/12 18:53
frankblack
frankblack (Show more)
Just can't stay away
Posts: 830
Since: 2005/6/13
#46

Re: PHP-Debugging without XOOPS

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

kaotik

Just can't stay away
Posted on: 2009/8/13 10:29
kaotik
kaotik (Show more)
Just can't stay away
Posts: 861
Since: 2004/2/19
#47

Re: PHP-Debugging without XOOPS

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

kaotik

Just can't stay away
Posted on: 2009/8/13 10:44
kaotik
kaotik (Show more)
Just can't stay away
Posts: 861
Since: 2004/2/19
#48

Re: PHP-Debugging without XOOPS

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

kaotik

Just can't stay away
Posted on: 2009/11/3 13:14
kaotik
kaotik (Show more)
Just can't stay away
Posts: 861
Since: 2004/2/19
#49

Re: PHP-Debugging without XOOPS

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

Mamba

Moderator
Posted on: 2011/4/4 7:33
Mamba
Mamba (Show more)
Moderator
Posts: 10873
Since: 2004/4/23
#50

Re: PHP-Debugging without XOOPS

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