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

Call to a member function loadTemplate() on null #248

Closed
vuongmao opened this issue Feb 27, 2020 · 1 comment
Closed

Call to a member function loadTemplate() on null #248

vuongmao opened this issue Feb 27, 2020 · 1 comment

Comments

@vuongmao
Copy link

vuongmao commented Feb 27, 2020

I'm using CakePHP3 with TwigView. However, I can not load any page on my application. I get the following error at the src/View/TwigView.php file. What am I doing wrong?

Call to a member function loadTemplate() on null

I can not use .twig and .tpl extensions too.

The routing configuration:

Router::scope('/', function (RouteBuilder $routes) {
    $routes->connect(
      '/',
      ['controller' => 'Man', 'action' => 'login']
    );
    $routes->connect(
      '/man/*',
      ['controller' => 'Man', 'action' => 'login']
    );
    $routes->fallbacks(DashedRoute::class);
});

TwigView Setting

// file: src/View/AppView.php
namespace App\View;
use WyriHaximus\TwigView\View\TwigView;

class AppView extends TwigView
{
    public function initialize()
    {
    }
}

Application class Setting

// file Application.php
    class Application extends BaseApplication
    {
        /**
         * {@inheritDoc}
         */
        public function bootstrap()
        {
            $this->addPlugin('WyriHaximus/TwigView');
            ....
        }
    }

Layout file

// file: Template/Layout/default.tpl

Controller

class AppController extends Controller
{
    public function initialize()
    {
        parent::initialize();
        $this->viewBuilder()->setLayout("default");
    }
}
@vuongmao
Copy link
Author

Oh that's lag knowledge

I fixed it by update the following function

. Adding the parent::initialize();

class AppView extends TwigView
{
    /**
     * Initialization hook method.
     *
     * Use this method to add common initialization code like loading helpers.
     *
     * e.g. `$this->loadHelper('Html');`
     *
     * @return void
     */

    public function initialize()
    {
        parent::initialize();
        $this->_ext = '.tpl';
    }
}

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

1 participant