Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Implementation of Hyperf View in Nano #9

Closed
ljfreelancer88 opened this issue Jul 13, 2020 · 13 comments
Closed

[Question] Implementation of Hyperf View in Nano #9

ljfreelancer88 opened this issue Jul 13, 2020 · 13 comments
Assignees

Comments

@ljfreelancer88
Copy link

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.

@huangzhhui
Copy link
Member

/assign @Reasno

@Reasno
Copy link
Member

Reasno commented Jul 14, 2020

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.

@ljfreelancer88
Copy link
Author

Thank you but how about the static resources configuration? Where to put this exactly?

@ljfreelancer88
Copy link
Author

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.

@Reasno
Copy link
Member

Reasno commented Jul 14, 2020

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,
        ],
    ]
]);

@ljfreelancer88
Copy link
Author

ljfreelancer88 commented Jul 15, 2020

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,
        ],
    ]
]);

@limingxinleo
Copy link
Member

'engine' => BladeEngine::class,
'mode' => Mode::SYNC,

@Reasno
Copy link
Member

Reasno commented Jul 16, 2020

hyperf/task is required unless you use 'mode' => Mode::SYNC,

@ljfreelancer88
Copy link
Author

ljfreelancer88 commented Jul 16, 2020

Sorry but 'mode' => Mode::SYNC doesn't work. Still giving me the same error.

@Reasno
Copy link
Member

Reasno commented Jul 17, 2020

I see no reason why it is not working. Here is a working/tested demo: https://github.com/Reasno/nano-demo

@ljfreelancer88
Copy link
Author

I've tried your demo, still got the same error. I switched back trying the basic example, it's weird because it suppose to work but again the same error.

Screenshot from 2020-07-17 10-44-58

@Reasno
Copy link
Member

Reasno commented Jul 17, 2020

composer remove hyperf/task

@ljfreelancer88
Copy link
Author

ljfreelancer88 commented Jul 18, 2020

composer remove hyperf/task works! Thank you. Greatly appreciated your help guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants