модель php use Phalcon Mvc Model Resultset Simple as Resultset class P

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
модель:
<?php
use Phalcon\Mvc\Model\Resultset\Simple as Resultset;
class Products extends \Phalcon\Mvc\Model {
public function initialize(){
$this->setSource('products');
}
public function getContentProducts () {
$products = new Products();
return new Resultset(null, $products, $products->getReadConnection()->query('SELECT * FROM products WHERE id > 0 LIMIT 5'));
}
}
?>
контроллер:
<?php
class ProductsController extends \Phalcon\Mvc\Controller {
public function indexAction(){
$this->view->setVar('_products', Products::getContentProducts());
}
}
?>
шаблон:
{% for product in _products %}
<li>
{{product.name}} - {{product.id}}
</li>
{% endfor %}