h2o-php icon indicating copy to clipboard operation
h2o-php copied to clipboard

(Question) Method invoking on object variable?

Open m3nt0r opened this issue 12 years ago • 2 comments

I can't find any example but i think it must be possible somehow. Also, what about array literals?

What i am looking for is

{{ myClass.someMethod(['a' = 'b', 2, 3, 4]) }}

I assign my objects via render(). I can {% debug %} them, just not call any method.

I thought about making "MyClass" a filter collection, but then it is still not clear if i can set arrays inside the template to use them as option hashes. And it would be bad for a couple other inheritance related reasons.

Is this planned or already supported?

m3nt0r avatar Jun 10 '12 06:06 m3nt0r

okay, found a generic solution to invoke methods with

$myClass->h2o_safe = get_class_methods($myClass);
$this->H2o->set($myClass->name, $myClass);

which allows me call methods without arguments

  1. How to pass arguments? I tried all markup i can think off but nothing gets through.
  2. How to create arguments? Is there a {% set foo = bar %} or maybe even something inline, like my example?

Well.. without 1 i don't need to know 2. Maybe i'll find it out but any hints are much appreciated.

m3nt0r avatar Jun 10 '12 07:06 m3nt0r

I think the idea is for you to treat it all in php side, then "render" the HTML with the template with simple variables only.

A bit fancier stuff could be using the filters (build your own), which accepts arguments.

brunobraga avatar Jun 27 '12 11:06 brunobraga