Skip to content

Commit

Permalink
Render's custom view path is now relative to views root.
Browse files Browse the repository at this point in the history
  • Loading branch information
sherifabdlnaby committed Mar 20, 2018
1 parent 6020e9f commit a21fd72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Core/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function getDefaultViewPath()
$router = App::getRouter();
$controllerDir = $router -> getRoute().DS.$router -> getController();
$templateName = $router -> getAction().'.html';
return VIEW_PATH.DS.$controllerDir.DS.$templateName;
return $controllerDir.DS.$templateName;
}

public function render(){
Expand Down
23 changes: 13 additions & 10 deletions Core/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ function render($layout = null, $viewPath = null, &$data = null, &$meta = null)
if (!$viewPath)
$viewPath = View::getDefaultViewPath();

//Relative to full path.
$viewPath = VIEW_PATH . DS . $viewPath;

//If no specific $data is not passed, use Controller's $this -> data instead
if (!$data)
$data = $this->data;
Expand All @@ -49,26 +52,26 @@ function render($layout = null, $viewPath = null, &$data = null, &$meta = null)


//Layout Paths
$layoutPath = LAYOUT_VIEW_PATH . DS . $layout . DS . 'layout.html';
$layoutPath = LAYOUT_VIEW_PATH . DS . $layout . DS . 'layout.html';
$layoutHeaderPath = LAYOUT_VIEW_PATH . DS . $layout . DS . 'header.html';
$layoutFooterPath = LAYOUT_VIEW_PATH . DS . $layout . DS . 'footer.html';
$layoutMetaPath = LAYOUT_VIEW_PATH . DS . $layout . DS . 'meta.html';
$layoutAlertsDir = LAYOUT_VIEW_PATH . DS . $layout . DS . 'alerts';
$layoutMetaPath = LAYOUT_VIEW_PATH . DS . $layout . DS . 'meta.html';
$layoutAlertsDir = LAYOUT_VIEW_PATH . DS . $layout . DS . 'alerts';

//A dummy Var to be passed to views that doesn't use controller's data (as View's $data is passed by reference for optimization)
$dummyVar = null;

//Create Header / Footer / Meta / Body Views Instances
$bodyObj = new View($data, $viewPath);
$headerObj = new View($dummyVar, $layoutHeaderPath);
$footerObj = new View($dummyVar, $layoutFooterPath);
$metaObj = new View($dummyVar, $layoutMetaPath, $meta);
$bodyObj = new View($data, $viewPath);
$headerObj = new View($dummyVar, $layoutHeaderPath);
$footerObj = new View($dummyVar, $layoutFooterPath);
$metaObj = new View($dummyVar, $layoutMetaPath, $meta);

//Do The Render
$content = $bodyObj->render();
$header = $headerObj->render();
$footer = $footerObj->render();
$meta = $metaObj->render();
$header = $headerObj->render();
$footer = $footerObj->render();
$meta = $metaObj->render();

//Render Alerts if exits
$alerts = "";
Expand Down

0 comments on commit a21fd72

Please sign in to comment.