[Question] Implementation of Hyperf View in Nano
ljfreelancer88 opened this issue · comments
Hi, how can I implement the Hyperf view
to render page in Nano? Since the structure of configuration of Hyperf and Nano is different.
Thanks in advance.
It is no different from standard hyperf.
$app->config([ 'view' => [ 'engine' => BladeEngine::class]);
$app->get('/', function(RenderInterface $render){
return $render->render('index', ['name' => 'Hyperf']);
});
Remember to require hyperf/view first.
Thank you but how about the static resources configuration? Where to put this exactly?
I got also this Missing Task Worker processes, please set server.settings.task_worker_num before use task.
error. But I'm not sure where to set this.
Put all relevant configurations in $app->config(). They follow the same structure in standard hyperf, except that the top-level keys are mapped from file names.
For example
$app->config([
'view' => [
'engine' => BladeEngine::class
],
'task' => [
'settings' => [
'task_worker_num' => 8,
'task_enable_coroutine' => false,
],
'callbacks' => [
// Task callbacks
SwooleEvent::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
SwooleEvent::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
],
],
'server' => [
'settings' => [
'document_root' => BASE_PATH . '/public',
'enable_static_handler' => true,
],
]
]);
I've tried to configuration below but got this Missing Task Worker processes, please set server.settings.task_worker_num before use task
error.
$app->config([
'db.default' => [
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 3306),
'database' => env('DB_DATABASE', 'nano'),
'username' => env('DB_USERNAME', 'username'),
'password' => env('DB_PASSWORD', 'password'),
],
'view' => [
'engine' => BladeEngine::class,
],
'task' => [
'settings' => [
'task_worker_num' => 8,
'task_enable_coroutine' => false,
],
'callbacks' => [
SwooleEvent::ON_TASK => [Hyperf\Framework\Bootstrap\TaskCallback::class, 'onTask'],
SwooleEvent::ON_FINISH => [Hyperf\Framework\Bootstrap\FinishCallback::class, 'onFinish'],
],
],
'server' => [
'settings' => [
'document_root' => __DIR__ . '/public',
'enable_static_handler' => true,
],
]
]);
'engine' => BladeEngine::class,
'mode' => Mode::SYNC,
hyperf/task is required unless you use 'mode' => Mode::SYNC,
Sorry but 'mode' => Mode::SYNC
doesn't work. Still giving me the same error.
I see no reason why it is not working. Here is a working/tested demo: https://github.com/Reasno/nano-demo
composer remove hyperf/task
composer remove hyperf/task
works! Thank you. Greatly appreciated your help guys.