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