bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

<F3:repeat and static function #141

Closed Kekec852 closed 11 years ago

Kekec852 commented 11 years ago

I get a error if i try to use static function that returns an array like this:

class User {
    public static function get_users() {
        return DB::sql("SELECT * FROM system_users;");
    }
}

And than in template:

<select name="user" class="smaller">
    <option value="-1">Select ...</option>
    <F3:repeat group="{{User::get_users()}}" value="{{@item}}">
        <option value="{{@item.UID}}">{{@item.username}}</option>
    </F3:repeat>
</select>

I get an error like this:

Invalid attribute: group="Array"

#0 C:/xampp/htdocs/WebApp/lib/F3/base.php:1749 F3::error(500,'Invalid attribute: group="Array"')
#1 {closure}(1024,'Invalid attribute: group="Array"','C:\xampp\htdocs\WebApp\lib\F3\f3markup.php',278,array('node'=>array('repeat'=>array('@attrib'=>array('group'=>'Array','value'=>''),0=>'
<option value=""></option>
')),'out'=>'','nkey'=>'repeat','nval'=>array('@attrib'=>array('group'=>'Array','value'=>''),0=>'
<option value=""></option>
'),'count'=>6,'akey'=>'group','aval'=>'Array','gval'=>'Array','gstr'=>'User::get_users()','gvar'=>'Array'))
#2 C:/xampp/htdocs/WebApp/lib/F3/f3markup.php:278 trigger_error('Invalid attribute: group="Array"')
#3 C:/xampp/htdocs/WebApp/lib/F3/f3markup.php:156 F3markup->build(array('repeat'=>array('@attrib'=>array('group'=>'Array','value'=>''),0=>'
<option value=""></option>
')))
#4 C:/xampp/htdocs/WebApp/lib/F3/f3markup.php:333 F3markup->build(array('@attrib'=>array('if'=>'User::__set_state()->flags | 0x08 == 0x08'),0=>'
<div id="dev-tools">
<h2 style="margin: 0;">Dev tools:</h2>
<h4 style="color: white;">Login as:</h4>
<form action="/WebApp/devtools/loginas" method="POST" class="form">
<p>
User: 
<select name="user" class="smaller">
<option value="-1">Select ...</option>
',1=>array('repeat'=>array('@attrib'=>array('group'=>'Array','value'=>''),0=>'
<option value=""></option>
')),2=>'
</select>
</p>
<input type="submit" class="button" value="Login as!" />
</form>
</div>
'))
bcosca commented 11 years ago

Not a bug. From the docs: "Fat-Free will replace the token with Array because it converts the token to a string, in much the same way that PHP displays the string Array when you try to echo a variable containing such type".

Kekec852 commented 11 years ago

I'm little confused.

So if i use:

F3::set("test", User::get_users());//from example

And then use it in:


<select name="user" class="smaller">
    <option value="-1">Select ...</option>
    <F3:repeat group="{{@test}}" value="{{@item}}">
        <option value="{{@item.UID}}">{{@item.username}}</option>
    </F3:repeat>
</select>

Will work as array but not if i use it directly in template?

<select name="user" class="smaller">
    <option value="-1">Select ...</option>
    <F3:repeat group="{{User::get_users()}}" value="{{@item}}">
        <option value="{{@item.UID}}">{{@item.username}}</option>
    </F3:repeat>
</select>
bcosca commented 11 years ago

Fixed in 3.0.