Код: Выделить всё
<?php Portlet::begin()?>
Код: Выделить всё
<?php Portlet::end()?>
Код: Выделить всё
<?php Portlet::begin()?>
Код: Выделить всё
<?php Portlet::end()?>
Код: Выделить всё
public static function begin($config = [])
{
$config['class'] = get_called_class();
/* @var $widget Widget */
$widget = Yii::createObject($config);
static::$stack[] = $widget;
$test="<div class='portlet'><br />";
return $test;
}
public static function end()
{
if (!empty(static::$stack)) {
$widget = array_pop(static::$stack);
if (get_class($widget) === get_called_class()) {
echo $widget->run();
$test2="</div>";
return $test2;
} else {
throw new InvalidCallException('Expecting end() of ' . get_class($widget) . ', found ' . get_called_class());
}
} else {
throw new InvalidCallException('Unexpected ' . get_called_class() . '::end() call. A matching begin() is not found.');
}
}
Код: Выделить всё
echo $widget->run();
нет не каких echo. Вывод должен происходить после инициализации. Вот после этого должна вывестись первая часть разметки <?Portlet::begin() ?> а после этого <?Portlet::end() ?> втораяsatoved писал(а): ↑2017.02.09, 12:37 Begin и end должны возвращать сам объект виджета, а вывод осуществляется обычным echo сразу.
У вас же выводится только:
А по умолчанию run() пустой.Код: Выделить всё
echo $widget->run();
Код: Выделить всё
public static function begin($config = [])
{
$config['class'] = get_called_class();
/* @var $widget Widget */
$widget = Yii::createObject($config);
static::$stack[] = $widget;
echo "<div class='portlet'><br />";
return $widget;
}
public static function end()
{
if (!empty(static::$stack)) {
$widget = array_pop(static::$stack);
if (get_class($widget) === get_called_class()) {
echo $widget->run();
echo "</div>";
return $widget;
} else {
throw new InvalidCallException('Expecting end() of ' . get_class($widget) . ', found ' . get_called_class());
}
} else {
throw new InvalidCallException('Unexpected ' . get_called_class() . '::end() call. A matching begin() is not found.');
}
}
Код: Выделить всё
<?= Portlet::begin() ?>
<?= Portlet::end() ?>