Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Working with an API (PHP) question

LEGEND ,
Jan 31, 2008 Jan 31, 2008
I am building a mini-app using an API into another back-end system. To
extract data from this system, I can use PHP lines like this -

$stats = $q->campaignStats($cid);

where the variable "$q" has been previously loaded with values.

What I want to know is - can I programatically generate this line? What I'd
LIKE to do would be something like this (analogous to the way that DW builds
query strings) -

$statsQuery = 'campaign' . $command . "($cid)"

and then I can set $command to any of a number of different values, e.g.,
"ClickStats", "Bounces", "Unsubscribes", etc.

Now - what I don't know how to do is to then reference this string in a way
that executes the command, as I'm fairly sure that -

$stats = $q->$statsQuery; would fail (but I'm going to try it of course).

Is there a special way to handle such things?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


TOPICS
Server side applications
214
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2008 Jan 31, 2008
.oO(Murray *ACE*)

>I am building a mini-app using an API into another back-end system. To
>extract data from this system, I can use PHP lines like this -
>
>$stats = $q->campaignStats($cid);
>
>where the variable "$q" has been previously loaded with values.
>
>What I want to know is - can I programatically generate this line? What I'd
>LIKE to do would be something like this (analogous to the way that DW builds
>query strings) -
>
>$statsQuery = 'campaign' . $command . "($cid)"
>
>and then I can set $command to any of a number of different values, e.g.,
>"ClickStats", "Bounces", "Unsubscribes", etc.
>
>Now - what I don't know how to do is to then reference this string in a way
>that executes the command, as I'm fairly sure that -
>
>$stats = $q->$statsQuery; would fail (but I'm going to try it of course).

The function name can be taken from a variable, so you can use something
like

$statsQuery = "campaign$command";
$stats = $q->$statsQuery($cid);

For other ways of calling such "dynamic" functions have a look at
call_user_func() and call_user_func_array() if necessary.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2008 Jan 31, 2008
Thanks, Micha! My earlier imagined way didn't work, not surprisingly!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:k7n4q39jppjrpi3sn2bcqvgdfu2s7g7geo@4ax.com...
> .oO(Murray *ACE*)
>
>>I am building a mini-app using an API into another back-end system. To
>>extract data from this system, I can use PHP lines like this -
>>
>>$stats = $q->campaignStats($cid);
>>
>>where the variable "$q" has been previously loaded with values.
>>
>>What I want to know is - can I programatically generate this line? What
>>I'd
>>LIKE to do would be something like this (analogous to the way that DW
>>builds
>>query strings) -
>>
>>$statsQuery = 'campaign' . $command . "($cid)"
>>
>>and then I can set $command to any of a number of different values, e.g.,
>>"ClickStats", "Bounces", "Unsubscribes", etc.
>>
>>Now - what I don't know how to do is to then reference this string in a
>>way
>>that executes the command, as I'm fairly sure that -
>>
>>$stats = $q->$statsQuery; would fail (but I'm going to try it of course).
>
> The function name can be taken from a variable, so you can use something
> like
>
> $statsQuery = "campaign$command";
> $stats = $q->$statsQuery($cid);
>
> For other ways of calling such "dynamic" functions have a look at
> call_user_func() and call_user_func_array() if necessary.
>
> Micha

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 31, 2008 Jan 31, 2008
LATEST
.oO(Murray *ACE*)

>Thanks, Micha!

You're welcome.

>My earlier imagined way didn't work, not surprisingly!

It would have required eval(), but usually you don't want to use that,
since eval() is evil and there's almost always a better way.

Micha
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines