ekandreas / bladerunner

WordPress plugin for Laravel Blade templating DEPRECATED
http://bladerunner.elseif.se
12 stars 1 forks source link

Controllers not working #77

Closed turnabout closed 6 years ago

turnabout commented 6 years ago

I'm using the distributed plugin (version 1.7) and I'm trying to use controllers inside my custom Wordpress theme. I'm trying to expose a variable from the controller inside the view, but it's coming up as undefined. It looks as if my controller file is being ignored.

This is my structure:

theme_root/
    tmpl-home.php

    controllers/
        Home.php

    views/
        home.blade.php
        master.blade.php

tmpl-home.php (Wordpress template)

bladerunner("views.home");

home.blade.php

@extends("views.master")

@section("content")
    {{ $mystr  }}
@endsection

controllers/Home.php

<?php

use Bladerunner\Controller;

class Home extends Controller
{
    public function mystr()
    {
        return "test";
    }
}

I've activated debugging with Debug::enable(); and it's coming up with these error messages:


(2/2) ErrorExceptionNotice: Undefined variable: mystr (View: /home/astudio/public_html/clients/micro/wp-content/themes/hop/views/home.blade.php)
--
in 1e3d9c989577fa7deb4763e945f6b6cef65da7c1.php (line 6)
at CompilerEngine->handleViewException(object(ContextErrorException), 0)in PhpEngine.php (line 45)
at PhpEngine->evaluatePath('/home/astudio/public_html/clients/micro/wp-content/uploads/.cache/1e3d9c989577fa7deb4763e945f6b6cef65da7c1.php',array('__env' => object(Factory), 'app' => object(Container)))in CompilerEngine.php (line 59)
at CompilerEngine->get('/home/astudio/public_html/clients/micro/wp-content/themes/hop/views/home.blade.php', array('__env' => object(Factory), 'app' =>object(Container)))in View.php (line 137)
at View->getContents()in View.php (line 120)
at View->renderContents()in View.php (line 85)
at View->render()in Blade.php (line 51)
at Blade->render('views.home', array())in helpers.php (line 21)
at view('views.home', array())in helpers.php (line 9)
at bladerunner('views.home')in tmpl-home.php (line 10)
at include('/home/astudio/public_html/clients/micro/wp-content/themes/hop/tmpl-home.php')in template-loader.php (line 74)
at require_once('/home/astudio/public_html/clients/micro/wp-includes/template-loader.php')in wp-blog-header.php (line 19)
at require('/home/astudio/public_html/clients/micro/wp-blog-header.php')in index.php (line 17)
(1/2) ContextErrorExceptionNotice: Undefined variable: mystr
--
in 1e3d9c989577fa7deb4763e945f6b6cef65da7c1.php (line 6)
at include('/home/astudio/public_html/clients/micro/wp-content/uploads/.cache/1e3d9c989577fa7deb4763e945f6b6cef65da7c1.php')in PhpEngine.php (line 43)
at PhpEngine->evaluatePath('/home/astudio/public_html/clients/micro/wp-content/uploads/.cache/1e3d9c989577fa7deb4763e945f6b6cef65da7c1.php',array('__env' => object(Factory), 'app' => object(Container)))in CompilerEngine.php (line 59)
at CompilerEngine->get('/home/astudio/public_html/clients/micro/wp-content/themes/hop/views/home.blade.php', array('__env' => object(Factory), 'app' =>object(Container)))in View.php (line 137)
at View->getContents()in View.php (line 120)
at View->renderContents()in View.php (line 85)
at View->render()in Blade.php (line 51)
at Blade->render('views.home', array())in helpers.php (line 21)
at view('views.home', array())in helpers.php (line 9)
at bladerunner('views.home')in tmpl-home.php (line 10)
at include('/home/astudio/public_html/clients/micro/wp-content/themes/hop/tmpl-home.php')in template-loader.php (line 74)
at require_once('/home/astudio/public_html/clients/micro/wp-includes/template-loader.php')in wp-blog-header.php (line 19)
at require('/home/astudio/public_html/clients/micro/wp-blog-header.php')in index.php (line 17)

Any idea what could be wrong?

ekandreas commented 6 years ago

Check this first: • Instead of Home.php, rename it to home.php • Ensure you have a home.php in the theme root.

turnabout commented 6 years ago

Done those two and it works now. I was under the impression it was fine for the controller file to have an uppercased first letter, since that's how it is in the readme's controller example.

Thanks for the fast help!

ekandreas commented 6 years ago

Perhaps it depends on which server you have? If it is case-sensitive?