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

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

Open
arnoson opened this issue Nov 11, 2023 · 4 comments

Comments

@arnoson
Copy link

arnoson commented Nov 11, 2023

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

  • scaffolding leaf mvc with the cli
  • remove leafs/blade and install leafs/bareui
  • in public/index.php replace Leaf\View::attach(\Leaf\Blade::class) with Leaf\View::attach(\Leaf\BareUI::class)
  • in config/view.php set 'viewEngine' => \Leaf\BareUI::class and replace View::blade()->configure($config['views'], $config['cache']) with Leaf\BareUI::config("path", $config['views'])

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
Copy link
Author

arnoson commented Nov 11, 2023

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

@mychidarko
Copy link
Member

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
Copy link
Member

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

@arnoson
Copy link
Author

arnoson commented Nov 12, 2023

Great, thanks for the quick reply!

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

2 participants