Skip to content

Commit

Permalink
up: update some web app service create logic, fix view render error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 18, 2022
1 parent a85ab77 commit 00661b8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
14 changes: 13 additions & 1 deletion app/Http/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inhere\Kite\Http;

use Inhere\Kite\Kite;
use function header;

/**
* Class Controller
Expand All @@ -17,6 +18,17 @@ abstract class Controller
*/
protected function render(string $viewPath, array $vars = []): void
{
Kite::webApp()->getRenderer()->renderOutput($viewPath, $vars);
Kite::webApp()->getRenderer()->render($viewPath, $vars);
}

/**
* @param string $html
*
* @return void
*/
protected function renderHTML(string $html): void
{
header('Content-Type: text/html');
echo $html;
}
}
12 changes: 12 additions & 0 deletions app/Http/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Inhere\Kite\Http\Controller;

use Inhere\Kite\Http\Controller;
use Inhere\Kite\Kite;

/**
* Class HomeController
Expand All @@ -15,4 +16,15 @@ public function index(): void
{
$this->render('home');
}

public function routes(): void
{
$str = Kite::webRouter()->toString();

$this->renderHTML(<<<HTML
<h1>Routes:</h1>
<pre>$str</pre>
HTML
);
}
}
1 change: 1 addition & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$router = Kite::webRouter();

$router->get('/', HomeController::class . '@index');
$router->get('/routes', HomeController::class . '@routes');
$router->get('/json5', JsonController::class . '@json5');
$router->get('/json', JsonController::class . '@format');

Expand Down
12 changes: 8 additions & 4 deletions app/Http/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use PhpPkg\EasyTpl\EasyTemplate;

$box->set('webRouter', function () {
return new Router();
return new Router([
'name' => 'kite-router',
]);
});

$box->set('renderer', function () {
Expand All @@ -19,7 +21,9 @@
});

$box->set('dispatcher', [
'class' => Dispatcher::class,
'class' => Dispatcher::class,
// prop settings
'actionSuffix' => '',
]);
'options' => [
'actionSuffix' => '',
],
]);

0 comments on commit 00661b8

Please sign in to comment.