outputhtml : allow to get multiple data from view (by array) and overwrite all the {XXX} by their value

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4712 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-11-15 13:10:29 +00:00
parent 522c5e7cfa
commit 6014d0587d

View File

@@ -5,6 +5,7 @@
*/ */
require_once ("domframework/output.php"); require_once ("domframework/output.php");
/** Display in HTML the data provided, with the layout support */ /** Display in HTML the data provided, with the layout support */
class outputhtml extends output class outputhtml extends output
{ {
@@ -59,7 +60,6 @@ class outputhtml extends output
"No data provided from view %s::%s"), "No data provided from view %s::%s"),
$viewClass,$viewMethod), $viewClass,$viewMethod),
500); 500);
$resView = $resView["content"];
} }
} }
@@ -68,7 +68,6 @@ class outputhtml extends output
if (! file_exists ($layout) && file_exists ("views/$layout.html")) if (! file_exists ($layout) && file_exists ("views/$layout.html"))
$layout = "views/$layout.html"; $layout = "views/$layout.html";
$layoutPage = $this->layoutVariables ($layout, $variable); $layoutPage = $this->layoutVariables ($layout, $variable);
$resView = str_replace ("{content}", $resView, $layoutPage);
} }
else else
{ {
@@ -86,23 +85,33 @@ class outputhtml extends output
</body> </body>
</html> </html>
EOT; EOT;
$resView = str_replace ("{content}", $resView, $layoutPage);
} }
// Do the title replacement in the replacement structure // Do the title replacement in the replacement structure
if (! isset ($replacement["{title}"]))
$replacement["{title}"] = $title;
if (! isset ($replacement["{flash}"])) if (! isset ($replacement["{flash}"]))
$replacement["{flash}"] = ""; $replacement["{flash}"] = "";
foreach ($replacement as $key=>$val) foreach ($replacement as $key=>$val)
$resView = str_replace ($key, $val, $resView); $layoutPage = str_replace ($key, $val, $layoutPage);
// All the entries coming from views in array are substitute in layout
// {content}, {title}
if (is_array ($resView))
{
foreach ($resView as $key => $val)
{
$layoutPage = str_replace ("{".$key."}", $val, $layoutPage);
}
}
else
$layoutPage = str_replace ("{content}", $resView, $layoutPage);
//echo $resView;exit; //echo $resView;exit;
// Manage the timestamp/md5sum for the external files managed by this // Manage the timestamp/md5sum for the external files managed by this
// server. // server.
$dom = new \DOMDocument (); $dom = new \DOMDocument ();
@$dom->loadHTML ($resView); @$dom->loadHTML ($layoutPage);
foreach (array ("script"=>"src", "link"=>"href", "img"=>"src") foreach (array ("script" => "src", "link" => "href", "img" => "src")
as $key=>$val) as $key=>$val)
{ {
$files = $dom->getElementsByTagName ($key); $files = $dom->getElementsByTagName ($key);
@@ -146,7 +155,7 @@ EOT;
// FIXME : Allow to manage variables in a layout provided in the variable, // FIXME : Allow to manage variables in a layout provided in the variable,
// without eval use // without eval use
if (! file_exists ($layout)) if (! file_exists ($layout))
return $layout; return "$layout doesn't exists";
extract ($variables); extract ($variables);
ob_start(); ob_start();
require ($layout); require ($layout);