renderer : display the flash informations automatically if it is defined. Allow to overwrite the layout page when calling the function

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2238 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-08-14 07:10:32 +00:00
parent 144842b4da
commit 78fe387468

View File

@@ -99,7 +99,7 @@ class renderer
}
/** @param mixed $data The data to display.*/
static function html ($viewclass, $viewmethod, $data,
static function html ($viewclass, $viewmethod, $data, $replacement = array(),
$layoutfile = "views/layout.html", $route = null)
{
if ($layoutfile !== false && ! file_exists ($layoutfile))
@@ -107,9 +107,36 @@ class renderer
require_once ("domframework/outputhtml.php");
if ($route === null)
$route = new route ();
// Return a $dataflash with the displayed flash in Bootstrap
$dataflash = "";
if (isset ($_SESSION["renderer"]["flash"]))
{
foreach ($_SESSION["renderer"]["flash"] as $flash)
{
$dataflash .= "<div class='alert ";
switch ($flash[0])
{
case 4: $dataflash .= "alert-danger";$alert = _("Error!");break;
case 3: $dataflash .= "alert-warning";$alert = _("Warning!");break;
case 2: $dataflash .= "alert-info";$alert = _("Info :");break;
case 1: $dataflash .= "alert-success";$alert = _("Success : ");break;
}
$dataflash .= " alert-dismissable'>\n";
$dataflash .= "<button type='button' class='close' data-dismiss='alert'";
$dataflash .= " aria-hidden='true'>&times;</button>\n";
$dataflash .= "<strong>$alert</strong> ".$flash[1]."\n";
$dataflash .= "</div>\n";
}
unset ($_SESSION["renderer"]["flash"]);
}
$html = new outputhtml ();
$replacement = array ("{baseurl}"=>$route->baseURL (),
"{baseurlresource}"=>$route->baseURLresource ());
$replacement = array_merge ($replacement,
array ("{baseurl}"=>$route->baseURL (),
"{baseurlresource}"=>$route->baseURLresource (),
"{flash}"=>$dataflash));
echo $html->out ($data,
FALSE,