21
hervet
Re: Ajax calls directly from Jquery
  • 2009/8/20 8:53

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


Quote:

kaotik wrote:
<script type="text/javascript" src="firebug.js"></script>
    <
script type="text/javascript" src="jquery-1.3.2.min.js"></script>

    <
script type="text/javascript">
  
$(
document).ready(function() {

$(
".button").click(function(event) {
    var 
name = $("input#name").val();
    var 
email = $("input#email").val();
    var 
phone = $("input#phone").val();
    var 
dataString 'name='name '&email=' email '&phone=' phone;
    
//console.log(name); //used with firebug

    
$("#box").load('myserv.php',dataString);
    });
});
  
</
script>

  <
form name="contact" action="">
    <
fieldset>
      <
label>Name</label>
      <
input type="text" name="name" id="name" size="30" value="" class="text-input" />
      
      <
label>Email</label>
      <
input type="text" name="email" id="email" size="30" value="" class="text-input" />
      
      <
label>Phone</label>
      <
input type="text" name="phone" id="phone" size="30" value="" class="text-input" />
      
        <
br />
      <
input type="button" name="button" class="button" id="button" value="Send" />
    </
fieldset>
  </
form>

    <
div id="box"></div>



have a look to this jQuery function, serialize().
For example :
var formContent = $("#myform").serialize();



22
hervet
A singleton to access your data classes
  • 2009/8/14 16:36

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


If you are using xoopsObject to manage the data access to your modules tables you must surely use this kind of code:
$myHandler xoops_getmodulehandler('mytable''mymodule');


The problem is that sometimes you declare this kind of code somewhere and you can't access it somewhere else, for example from a function.
The other problem is that you have to repeat this kind of code each time you need a handler.

With this class, you can access to any table's handler from anywhere without multiplying the objects.
You just need to do something like this :
$oledrion_handlers oledrion_handler::getInstance();
$count $oledrion_handlers->h_oledrion_products->getRecommendedCount();


You can even access a handler like this:
$count oledrion_handler::getInstance()->h_oledrion_products->getRecommendedCount();


The advantage, as I said, is that you can access your handlers from anywhere without creating several times the same object and all your handlers are centralized in one place.
Handlers are loaded on demand and stay in memory for further use.

<?php
/**
 * ****************************************************************************
 * oledrion - MODULE FOR XOOPS
 * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         oledrion
 * @author             Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 *
 * Version : $Id:
 * ****************************************************************************
 */

/**
 * Chargement des handlers utilisés par le module
 */
class oledrion_handler
{
    
/**
     * Contient la liste des handlers disponibles
     *
     * @var array
     */
    
private $handlersNames = array('oledrion_manufacturer''oledrion_products''oledrion_productsmanu''oledrion_caddy''oledrion_cat''oledrion_commands''oledrion_related''oledrion_vat''oledrion_votedata''oledrion_discounts''oledrion_vendors''oledrion_files''oledrion_persistent_cart''oledrion_gateways_options');

    
/**
     * Contient l'unique instance de l'objet
     * @var object
     */
    
private static $instance false;

    
/**
     * Réceptacle des handlers
     *
     * @var array
     */
    
public static $handlers null;

    
/**
     * Méthode chargée de renvoyer les handlers de données en les chargeant à la volée
     *
     * @param string $name
     * @return mixed    Null si on échoue, sinon l'objet demandé
     */
    
function __get($name)
    {
        if(
substr($name02) != 'h_') {
            return 
null;
        }
        if(!
in_array(substr($name2), $this->handlersNames)) {
            return 
null;
        }
        if(!isset(
$this->handlersNames[$name])) {
            
$this->handlers[$name] = xoops_getmodulehandler(substr($name2), OLEDRION_DIRNAME);
        }
        return 
$this->handlers[$name];
    }

    private function 
__construct()
    {
        
$this->handlers = array();
    }

    
/**
     * Retourne l'instance unique de la clanss
     *
     * @return object
     */
    
public static function getInstance()
    {
        if (!
self::$instance instanceof self) {
              
self::$instance = new self;
        }
        return 
self::$instance;
    }
}
?>


Note, this class requires Php 5.



23
hervet
Parameters class for methods of classes ...
  • 2009/8/13 17:45

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


All my projects are made of classes and each classes are made of methods.
Sometimes those methods contains several parameters. I estimate that over 4
parameters it's not possible to maintain easily those methods (and there
clients).

For example, in a method like this :
class myclass
{
    function 
mymethod($param1$param2$param3$param4$param5)
    {
    
    }
}

There are too much parameters, it's difficult to maintain them in the
method itself and in the clients of this method, it's hard to remember
what parameters are used for (each of them).
If your parameters' list grow, it's becoming a nightmare.

So I have made a new class to solve this.
Put the class at the end of this post in a Php file.
This class will only runs with Php 5 (a recent version).

When you create a method which needs several parameters, like this one :
function mymethod($param1$param2$param3$param4$param5)
    {
    
    }


You change its declaration's code to this :
function mymethod(mymodule_parameters $parameters)
    {
    
    }


Then in your class, you set the default's values like this.
For example, if your method needs 4 parameters, "start", "limit", "sort" and "order", you merge the parameters passed to your method with the default values awaited like this :
(the extend method mimic the jQuery's equivalent)

$parameters $parameters->extend(new mymodule_parameters(array('start' => 0'limit' => 10'sort' => 'firstname''order' => 'ASC')));


So, your method looks like this :
function mymethod(mymodule_parameters $parameters)
    {
        
$parameters $parameters->extend(new mymodule_parameters(array('start' => 0'limit' => 10'sort' => 'firstname''order' => 'ASC')));
        
$criteria = new Criteria('myfield'10'>');
        
$criteria->setSort($parameters['sort']);
        
$criteria->setOrder($parameters['order']);
        
$criteria->setStart($parameters['start']);
        
$criteria->setLimit($parameters['limit']);
        
    }


It's like using associative arrays as parameters but with more power because the class extends ArrayObject (from the SPL)
Now I can call this method like this :

1/ "Without" parameters :
$myobject->mymethod(new mymodule_parameters());


2/ With only one parameter:
$myobject->mymethod(new mymodule_parameters(array('sort' => 'lastname')));


3/ I can define my parameters elsewhere, as I want and pass them to the method, later:
$parameters = new mymodule_parameters(array('sort' => 'lastname'));
$myobject->mymethod($parameters);


or like this (chaining):
$parameters = new mymodule_parameters();
$parameters->setSort('lastname')->setStart($start)->setLimit(10)->setOrder('DESC');
$myobject->mymethod($parameters);


or even like this (like an array):
$parameters = new mymodule_parameters();
$parameters['sort'] = 'lastname';
$parameters['start'] = $start;
$parameters['limit'] = 10;
$parameters['order'] = 'DESC';
$myobject->mymethod($parameters);


or like this too (as class properties):
$parameters = new mymodule_parameters();
$parameters->sort 'lastname';
$parameters->start $start;
$parameters->limit 10;
$parameters->order 'DESC';
$myobject->mymethod($parameters);


You can display a parameter in two ways:
echo $param['sort'];
echo 
$param->limit()


I have just made this class so it can contains errors, it's not yet fully tested.

PROS
- When you call a method, you can call it with parameters in any order you want
- When you call a method, you can just pass the parameters you want
- You are using named parameters
- It's more easy to maintain (for the clients of the methods) when your parameters change (you don't have to review all your code)

CONS
- It must be slower (but the class extends ArrayObject which is made in C)
- In IDEs like Zend Studio or Netbeans, the autocompletion of your methods can lake the parameters (except if you use phpDocumentor comments)
- Even when you want to call a method without giving it parameters, you have to pass it a "mymodule_parameters" object
But it can be solved by changing your methods declarations.

Here is the full code of my class:
<?php
/**
 * ****************************************************************************
 * mymodule - MODULE FOR XOOPS
 * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         mymodule
 * @author             Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 *
 * Version : $Id:
 * ****************************************************************************
 */

/**
 * Class used for parameters passing to classes methods
 *
 * @copyright       Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         mymodule
 * @author             Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
 * @version 1.0
 *
 * Example :
 *
 * // Instanciate it like this
 * $param = new mymodule_parameters();
 *
 * // Create several parameters in one time:
 * $param->setLimit(10)->setSort('manu_name');
 *
 * // Set a parameter with the array convention:
 * $param['sort'] = 'first_name';
 *
 * // Set a parameter as a class property:
 * $param->order = 'DESC';
 *
 * // Display a parameter, first way:
 * echo "<br />value=".$param['sort'];    // DESC
 *
 * // Another method to show it, as a class method:
 * echo $param->limit();    // 10
 *
 * // Set the default values
 * $newParameters = $param->extend(new mymodule_parameters(array('sort' => 'firstName', 'start' => 0, 'limit' => 15, 'showAll' => true)));
 *
 */
class mymodule_parameters extends ArrayObject
{
    
/**
     * Permet de valoriser un indice de la classe comme si c'était une propriété de la classe
     *
     * @example $enregistrement->nom_du_champ = 'ma chaine'
     *
     * @param string $key    Le nom du champ à traiter
     * @param mixed $value    La valeur à lui attribuer
     * @return object
     */
    
function __set($key$value)
    {
        
parent::offsetSet($key$value);
        return 
$this;
    }

    
/**
     * Valorisation d'un indice de la classe en utilisant un appel de fonction basé sur le principe suivant :
     *         $maClasse->setLimit(10);
     * Il est possible de chainer comme ceci : $maClasse->setStart(0)->setLimit(10);
     *
     * @param string $method
     * @param mixed $args
     * @return object
     */
    
function __call($method$args)
    {
        if(
substr($method03) == 'set') {
            
parent::offsetSet(strtolower(substr($method31)).substr($method4), $args[0]);
            return 
$this;
        } else {    
// Affichage de la valeur
            
return parent::offsetGet($method);
        }
    }

    
/**
     * Méthode qui essaye de faire la même chose que la méthode extend() de jQuery
     *
     * On lui passe les valeurs par défaut que l'on attend et la méthode les compare avec les valeurs actuelles
     * Si des valeurs manquent, elles sont ajoutées
     *
     * @param mymodule_parameters $defaultValues
     * @return mymodule_parameters
     */
    
function extend(self $defaultValues)
    {
        
$result = new self;
        
$result $this;
        foreach(
$defaultValues as $key => $value) {
            if(!isset(
$result[$key])) {
                
$result[$key] = $value;
            }
        }
        return 
$result;
    }
}
?>



24
hervet
Re: nuSoap
  • 2009/8/11 9:43

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


I mean that XOOPS SHOULD require Php 5.



25
hervet
Re: nuSoap
  • 2009/8/11 8:08

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


No, Php5 should already be supported, that's all.
Taking late with support for Php 5 is giving late to Xoops, one more time.

When I see the time required to release a version (when it is released) I can imagine that the 2.5 will be released in, at least, 1 year.

Xoops will be, one more time, the last project to support something, in this case Php 5.



26
hervet
Re: First comments on 2.4
  • 2009/8/11 8:04

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


Quote:

Quote:
Closing tag yes or no, this is the question.
I should always add the closing tags for the sake of clear and clean code.

I even don't understand how this can be discussed !
A Php script starts with <?php and end with ?>
If you can't do it, don't code



27
hervet
Re: nuSoap
  • 2009/8/10 17:25

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


So it's useless to develop some technologies that are already obsoletes !



28
hervet
nuSoap
  • 2009/8/10 16:08

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


What's the interest to use it ?
Php 5 comes with, by default, a SOAP server.

How long are we going to use some completly obsolte technologies ?



29
hervet
Re: PHP-Debugging without XOOPS
  • 2009/8/9 11:35

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


Quote:

frankblack wrote:
Feels like an accolade to hear this from you. Really! I admire your whole work, so this compliment makes me feel proud.

You should not, you are much more better than me.
Working with good tools is still more pleasant and with this tool it's a real pleasure.

I have always wanted to do a such work for FirePhp and FireBug but never took the time to do it.

I will just permit myself to modify your example like this :
require_once XOOPS_ROOT_PATH.'/Frameworks/FirePHPCore/FirePHP.class.php';
FirePHP::getInstance(true)->log($yourvariable);

it is less readable but it avoid to declare a variable
It's only for the case where you want to see one variable's content.

If the different methods of the XOOPS kernel and classes could chain like this, it will be very useful.



30
hervet
Re: PHP-Debugging without XOOPS
  • 2009/8/8 17:08

  • hervet

  • Friend of XOOPS

  • Posts: 2267

  • Since: 2003/11/4


Quote:

frankblack wrote:
V1.3 is released

This is really the best enhancement for XOOPS developpers !




TopTop
« 1 2 (3) 4 5 6 ... 139 »



Login

Who's Online

228 user(s) are online (149 user(s) are browsing Support Forums)


Members: 0


Guests: 228


more...

Donat-O-Meter

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

Latest GitHub Commits