Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Accessing namespace models in volt

Hi, I have all my models with namespace MyApp\Models My question is how to directly access the model directly from volt?

For example I have a model of foo in Foo.php:

<?php
namespace MyApp\Models;
class Foo extends \Phalcon\Mvc\Model 
{
}

I want to retrive all record in Foo in my bar.volt like

{% for x in MyApp\Models\Foo.find() %}
    Name: {{x.name}}<br>
{% endfor %}

But it will generate error. Pls Help.



82.7k
Accepted
answer

Calling static functions in volt is still not supported, we hope support it soon, from now you can use php there:

<?php foreach (MyApp\Models\Foo::find() as $x) { ?>
Name: {{x.name}}<br>
<?php } ?>

That's worked great. Volt is awesome :) Thanks Phalcon.



11.6k

very good, in volt template ,can use php tag?