leafsphp / leafMVC

Lightweight framework for rapid development based on Leaf
https://leafphp.dev/docs/mvc/
46 stars 7 forks source link

Error when using BareUI: `Call to undefined method Leaf\BareUI::configure()` #22

Closed arnoson closed 2 months ago

arnoson commented 11 months ago

I try to get this running with BareUi instead of Blade templates. What I did was

But I get the following error:

Error thrown with message "Call to undefined method Leaf\BareUI::configure()"

Stacktrace:
#10 Error in <my-project>/vendor/leafs/mvc-core/src/globals/functions.php:43
#9 view in <my-project>/vendor/leafs/mvc-core/src/globals/functions.php:63
#8 render in <my-project>/app/routes/_app.php:7
#7 Leaf\Core:{closure} in <my-project>/vendor/leafs/router/src/Router/Core.php:531
#6 call_user_func_array in <my-project>/vendor/leafs/router/src/Router/Core.php:531
#5 Leaf\Router\Core:invoke in <my-project>/vendor/leafs/router/src/Router/Core.php:521
#4 Leaf\Router\Core:handle in <my-project>/vendor/leafs/router/src/Router/Core.php:466
#3 Leaf\Router\Core:run in <my-project>/vendor/leafs/leaf/src/App.php:382
#2 Leaf\App:run in <my-project>/vendor/leafs/mvc-core/src/Core.php:121
#1 Leaf\Core:runApplication in <my-project>/public/index.php:110
#0 require_once in <my-project>/index.php:28

Am I doing something wrong and the mvc requires more config to change the view engine?

arnoson commented 11 months ago

This is fixed when changing configure() to config() in /mvc-core/src/globals/functions.php, so I guess BladeUi should also impement configure()?

mychidarko commented 11 months ago

Hi @arnoson sorry about this, it seems our documentation did not completely cover the steps to switch to bareui. You will need to swap out your config/view.php with this config:

<?php

use Leaf\View;

return [
    /*
    |--------------------------------------------------------------------------
    | Template Engine [EXPERIMENTAL]
    |--------------------------------------------------------------------------
    |
    | Leaf MVC unlike other frameworks tries to give you as much control as
    | you need. As such, you can decide which view engine to use.
    |
    */
    'viewEngine' => \Leaf\BareUI::class,

    /*
    |--------------------------------------------------------------------------
    | Custom config method
    |--------------------------------------------------------------------------
    |
    | Configuration for your templating engine.
    |
    */
    'config' => function ($config) {
        View::bareui()->config($config['views']);
    },

    /*
    |--------------------------------------------------------------------------
    | Custom render method
    |--------------------------------------------------------------------------
    |
    | This render method is triggered whenever render() is called
    | in your app if you're using a custom view engine.
    |
    */
    'render' => function ($view, $data = []) {
        return View::bareui()->render($view, $data);
    },
];
mychidarko commented 11 months ago

This will teach Leaf how to work with BareUI or ant templating engine of your choice.

arnoson commented 11 months ago

Great, thanks for the quick reply!