There is a view widget
class ItemsWidget extends Widget { public $items; public function init() { parent::init(); $this->items = Items::find()->asArray()->all(); ob_start(); // что-то вроде этого, но не работает for ($i=0; $i < count ($this->items) ; $i++ ) { extract($this->items[$i]); } } public function run() { $content = ob_get_clean(); return Html::encode( $content ); } } The view uses the Smarty templating engine, although it doesn’t play a role in this case.
{ItemsWidget assign='widget'} // как обойтись без цикла здесь ? <div>{$widget.items.title}</div> {/ItemsWidget} How can I iterate through the array and return the finished block of code?
{ItemsWidget assign='widget'} {foreach $widget.items as $item} <div>{$item.title}</div> {/foreach} {/ItemsWidget}somehow confuses me. I understand there is a way to do this in the ItemsWidget.php file - Guest