Closed fiskhandlarn closed 3 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.
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. :)
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
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.
@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.
We don't use Trait at all in controllers. So I have no clue here.
You need to provide a class that extends Bladerunner\Controller as in the example.
@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.
@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)
@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.
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.
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.
@ekandreas I understand! Could you please provide a working example for the original issue? :)
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)
@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.
Possible but the core functions for the controllers is rewritten in bladerunner.
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?
@ekandreas Any news on this? :)
No, because I don't understand the need or why this is a problem. Perhaps you could describe the issue?
@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.
Hi! This is a deprecated package. Please use https://github.com/EFTEC/BladeOne instead!
controllers/footer.php
:Since the
footer.php
template is included in thefront-page.php
template (for example), this repo only looks for and includescontrollers/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 incontrollers/front-page.php
tofooter.blade.php
(this doesn't seem to work either).