Skip to content

Commit

Permalink
1. update example
Browse files Browse the repository at this point in the history
2. update web/view clsss
  • Loading branch information
scarwu committed Aug 14, 2018
1 parent 25ef5e2 commit 46b963d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 53 deletions.
23 changes: 14 additions & 9 deletions example/Web/controllers/AboutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,41 @@

class AboutController extends Controller
{
/**
* Lifecycle Functions
*/
public function up() {
$this->view->setLayoutPath('index');
}

public function down() {
$this->res->html($this->view->render());
}

/**
* Actions
*/
public function defaultAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('about/default');
$this->view->setData([
'title' => 'Oni - About / Default Page'
]);

$this->res->html($this->view->render());
}

public function mvcAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('about/mvc');
$this->view->setData([
'title' => 'Oni - About / MVC Page'
]);

$this->res->html($this->view->render());
}

public function mvvmAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('about/mvvm');
$this->view->setData([
'title' => 'Oni - About / MVVM Page'
]);

$this->res->html($this->view->render());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Api/Test Controller
* Api/Basic Controller
*
* @package Oni
* @author Scar Wu
Expand All @@ -12,10 +12,13 @@

use Oni\Web\Controller\Rest as Controller;

class TestController extends Controller
class BasicController extends Controller
{
private $data;

/**
* Lifecycle Functions
*/
public function up()
{
$this->data = [
Expand All @@ -39,23 +42,30 @@ public function up()
];
}

public function down() {
var_dump($this->data);
}

/**
* Actions
*/
public function getAction()
{
var_dump($this->data);

}

public function postAction()
{
var_dump($this->data);

}

public function putAction()
{
var_dump($this->data);

}

public function deleteAction()
{
var_dump($this->data);

}
}
20 changes: 14 additions & 6 deletions example/Web/controllers/MainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,22 @@

class MainController extends Controller
{
/**
* Lifecycle Functions
*/
public function up() {
$this->view->setLayoutPath('index');
}

public function down() {
$this->res->html($this->view->render());
}

/**
* Actions
*/
public function defaultAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('main/default');
$this->view->setData([
'title' => 'Oni - A Lightweight PHP Framework for Web & CLI',
Expand All @@ -40,18 +53,13 @@ public function defaultAction()
]
]
]);

$this->res->html($this->view->render());
}

public function errorAction()
{
$this->view->setLayoutPath('index');
$this->view->setContentPath('main/error');
$this->view->setData([
'title' => 'Oni - Error Page'
]);

$this->res->html($this->view->render());
}
}
61 changes: 29 additions & 32 deletions src/Oni/Web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,56 +137,53 @@ public function getContentPath()
}

/**
* Load Content
* Load Partial
*
* @param string $_sub_path
*
* @return string
*/
private function loadContent()
private function loadPartial($_sub_path)
{
$_path = $this->getAttr('path');
$_ext = $this->getAttr('ext');

$_fullpath = "{$_path}/{$this->contentPath}.{$_ext}";
$_result = '';

if (file_exists($_fullpath)) {
foreach ($this->data as $_key => $_value) {
$$_key = $_value;
}
if (is_string($_sub_path)) {
$_path = $this->getAttr('path');
$_ext = $this->getAttr('ext');
$_fullpath = "{$_path}/{$_sub_path}.{$_ext}";

if (file_exists($_fullpath)) {
foreach ($this->data as $_key => $_value) {
$$_key = $_value;
}

ob_start();
include $_fullpath;
$_result = ob_get_contents();
ob_end_clean();
ob_start();
include $_fullpath;
$_result = ob_get_contents();
ob_end_clean();
}
}

return $_result;
}

/**
* Load Content
*
* @return string
*/
private function loadContent()
{
return $this->loadPartial($this->contentPath);
}

/**
* Render
*
* @return string
*/
public function render()
{
$_path = $this->getAttr('path');
$_ext = $this->getAttr('ext');

$_fullpath = "{$_path}/{$this->layoutPath}.{$_ext}";
$_result = '';

if (file_exists($_fullpath)) {
foreach ($this->data as $_key => $_value) {
$$_key = $_value;
}

ob_start();
include $_fullpath;
$_result = ob_get_contents();
ob_end_clean();
}

return $_result;
return $this->loadPartial($this->layoutPath);
}
}

0 comments on commit 46b963d

Please sign in to comment.