ekandreas / bladerunner

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

Use controller classes for included wordpress templates #69

Closed fiskhandlarn closed 3 years ago

fiskhandlarn commented 6 years ago

controllers/footer.php:

<?php

namespace App;

use Bladerunner\Controller;

class Footer extends Controller
{
    public function images()
    {
        return ["image", "image2"];
    }
}

Since the footer.php template is included in the front-page.php template (for example), this repo only looks for and includes controllers/front-page.php. Is there a way to make this repo also include the footer controller if the footer template is included? Or at least expose properties defined in controllers/front-page.php to footer.blade.php (this doesn't seem to work either).

ekandreas commented 6 years ago

So if I understand you right you would like all includes in a view activate a controller if one exists? Sounds like we then violates the MVC structures but I really like the idéa. Perhaps we have to extend the Bladerunner with hooks and filter so that this is possible. But I think that the Blade compilation is quite hard to get around in that way.

ekandreas commented 6 years ago

Slack?

fiskhandlarn commented 6 years ago

Don't have an @elseif.se email address? Contact your Workspace Administrator for an invitation.

X)

If it's hard to activate controllers for all template/view includes I would at least like to have the option to expose controller properties/methods to included templates. :)

darrenjacoby commented 6 years ago

If I understand correctly, you can do this using Controller components/partials, that would be the correct way. https://github.com/soberwp/controller#creating-components

ekandreas commented 6 years ago

Yes, exactly the same way but you have to inherit/extend the class with a bladerunner class and set the right map (if not using ./controllers/ in your theme.

fiskhandlarn commented 6 years ago

@darrenjacoby @ekandreas I've tried the Trait-example from https://github.com/soberwp/controller#creating-components with no luck:

Fatal error: Trait 'App\Images' not found in \public\themes\inuheat\controllers\Single.php on line 9

I've tried placing the Images.php file in the same folder as Single.php, and in the folders partials, App and app. I've also tried removing namespace App; from both files. The same problem persists.

ekandreas commented 6 years ago

We don't use Trait at all in controllers. So I have no clue here.

ekandreas commented 6 years ago

You need to provide a class that extends Bladerunner\Controller as in the example.

darrenjacoby commented 6 years ago

@fiskhandlarn are you using the dev-master version? That has PSR4 loading.

Just to note, Bladerunner/Controller is a fork/duplicate (more or less) of the soberwp Controller. The author of this repo would need to update their code. if they're using the older version, then PSR4 loading of traits won't work.

fiskhandlarn commented 6 years ago

@ekandreas The example in https://github.com/soberwp/controller#creating-components consists of one Trait and one Controller. I have changed that example to using Bladerunner\Controller instead, forgot to write that. If this repo doesn't use Traits I'm not sure what to do with the example provided and your comment "Yes, exactly the same way". X)

fiskhandlarn commented 6 years ago

@darrenjacoby do you mean for this repo (in that case: yes)? i'm not using https://github.com/soberwp/controller at all, I was only trying the example from there with this repo.

ekandreas commented 6 years ago

Sorry for that :-) Not EXACTLY but it is in the same spirit and way to solve the controller requirement. The code is fetched from soberwp but the functions is not implemented in the exact same way. I have removed the bloated code to get a more strict and easy way to do it.

darrenjacoby commented 6 years ago

The code looks copied from https://github.com/soberwp/controller, so may be outdated. I'm working on a new release, so will def be outdated soon.

I would recommend the author of this repo use Controller as a Composer dependency vs copying/pasting.

fiskhandlarn commented 6 years ago

@ekandreas I understand! Could you please provide a working example for the original issue? :)

fiskhandlarn commented 6 years ago

Or maybe that's not yet possible when rereading this thread. I was confused by @darrenjacoby's suggested solution and you saying that it should work the same way, when it doesn't. X)

darrenjacoby commented 6 years ago

@ekandreas

Only one function has been added to Controller.php, the rest is the same. The correct way would be to use the Controller.php class from soberwp/Controller using Composer to ensure it's always the latest version and write that additional view method in a separate Class. Trust me, there are bugs in older versions.

The new version of Controller will have getters for all params, and fix a lot of bugs.

ekandreas commented 6 years ago

Possible but the core functions for the controllers is rewritten in bladerunner.

vpillinger commented 6 years ago

So if I understand correctly, there is nothing stopping us from

1) Making trait "footer" 2) Including that in a base controller? 3) Extending that base controller in all our controllers to get "footer" trait added to them

How does this relate to layouts? In other words, can I have a controller for my layout that takes care of the header/footer and not have to worry about doing the above?

fiskhandlarn commented 6 years ago

@ekandreas Any news on this? :)

ekandreas commented 6 years ago

No, because I don't understand the need or why this is a problem. Perhaps you could describe the issue?

fiskhandlarn commented 6 years ago

@ekandreas I thought you already did? :) Do you need a more thorough description of the issue than the one given initially (and the additions by me, @darrenjacoby and @vpillinger)?

If the main issue cannot be fixed I would like to have the option to expose controller properties/methods to included templates, if possible.

ekandreas commented 3 years ago

Hi! This is a deprecated package. Please use https://github.com/EFTEC/BladeOne instead!