TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-06-2009, 09:11 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default __call

Hi!

I'm intrigued(spelling?) how this really works.
I have it set up like this:

In my DB object
PHP Code:
public function __call($function$params)
    {
        
        if(
is_object($this->DB_Helper))
        {
            
            return 
$this->DB_Helper->$function($params[0]);
            
        }
        
        
TANAXIA_CORE::error('DB_Helper is not loaded. Check out database config file.');
        return 
false;
        
    } 
And then my DB_helper objects' functions looks like this(for example):
PHP Code:
public function order_by($order$how)
    {
        
        
$this->order_by[$order] = $how;
        
        return 
$this;
        
    } 
But if I call it like $db->order_by('test_cat', 'DESC')
that gets on ONE line, so when it calls the function the function will be:

$this->DB_Helper->order_by('test_cat, DESC');

Leaving the second option out.. how can I get it to actually set the two parameters(or even more parameters) ??
__________________
Tanax is offline  
Reply With Quote
Old 04-06-2009, 09:42 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You could use call_user_func_array.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Tanax (04-07-2009)
Old 04-06-2009, 10:54 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Thanks! You mean I should use that in the __call function?
PHP Code:
public function __call($function$params)
{
// split the params so I get an array $array
call_user_func_array($this->DB_Helper->$function$array); 
Like that?
Is this the most efficiant/best way to do this?
__________________
Tanax is offline  
Reply With Quote
Old 04-06-2009, 11:01 PM   #4 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

PHP Code:

return call_user_func_array(array($this->DB_Helper,$function),$params); 
Enfernikus is offline  
Reply With Quote
The Following User Says Thank You to Enfernikus For This Useful Post:
Tanax (04-07-2009)
Old 04-07-2009, 08:59 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Worked like a charm.
Thanks alot!!
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:32 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design