Оценить функции данных - PullRequest
       1

Оценить функции данных

0 голосов
/ 10 октября 2011

Я получил:

function notification($text, $info = FALSE, $title = FALSE) {
    global $layout_name;
    return '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}

Интересно, есть ли способ распечатать его без использования echo notification('text...', FALSE/TRUE, 'some title');

Только только notification('text...', FALSE/TRUE, 'some title'); (без echo)?

Если так, как это можно сделать?

Ответы [ 3 ]

0 голосов
/ 10 октября 2011

Вы можете использовать эту функцию вместо:

function notification($text, $info = FALSE, $title = FALSE) {
    global $layout_name;
    echo '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}

, но она все еще повторяет результаты, невозможно избежать использования функции echo.

PASSING BYREF

функция будет выглядеть примерно так, как показано ниже, но вы должны изменить ее в соответствии со своими потребностями:

function notification($text, $info = FALSE, $title = FALSE, &$content) {
    global $layout_name;
    $content .= '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}

Теперь, если вы используете эту функцию и передаете$content переменная, она изменит содержимое $ вне функции.обратите внимание, что передача по ссылке осуществляется в php путем добавления & перед переменной $VAR.

0 голосов
/ 10 октября 2011

Нет, это нельзя сделать с помощью eval. Но если вы говорите, что в противном случае использовали бы $content .= ... назначения, то измените свою функцию для этого.

function notification($text, $info = FALSE, $title = FALSE) {
    global $layout_name;
    global $content;
    $content .= '<div class="SmallBox"><div class="MessageContainer"><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeLeftTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeRightTop" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="'.($info ? "Valid" : "Error").'Message"><div class="BoxFrameVerticalLeft" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="BoxFrameVerticalRight" style="background-image:url('.$layout_name.'/images/content/box-frame-vertical.gif);" /></div><div class="AttentionSign" style="background-image:url('.$layout_name.'/images/content/'.(!$info ? 'attentionsign.gif' : 'valid.png').');" /></div><b>'.(!$title ? (!$info ? 'Wystąpiły następujące błędy:' : 'Sukces!') : $title).'</b><br/>'.$text.'</div><div class="BoxFrameHorizontal" style="background-image:url('.$layout_name.'/images/content/box-frame-horizontal.gif);" /></div>    <div class="BoxFrameEdgeRightBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div><div class="BoxFrameEdgeLeftBottom" style="background-image:url('.$layout_name.'/images/content/box-frame-edge.gif);" /></div></div></div>';
}

Это довольно глупо делать это. Но для лени это сработало бы, если бы все приложения совместно использовали эту $content выходную переменную в глобальной области видимости. (Читайте: требуется global $content везде, где это было определено ранее.)

0 голосов
/ 10 октября 2011

Текст возвращается, и функция является PHP, поэтому вы должны либо вывести результат самостоятельно, либо изменить функцию так, чтобы она выводила сам текст.

...