For anyone who is familiar with Sage 10, I am trying to get View Composers working outside of the default app/View/Composers
directory. I have another directory Composers
inside the parent directory of the Sage 10 directory and loaded it in correctly through PSR-4. This is working fine.
However, it does not seem to work. I wonder if I have to register my 'custom' Composer directory somewhere, but the documentation on Sage 10 is very shallow to non-existent.
So in the parent of my Sage dir, there is a Composers dir that gets loaded though PSR-4 containing an Application.php
which looks like this:
<?php
namespace Composers;
use RootsAcornViewComposer;
class Application extends Composer
{
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'partials.header',
];
/**
* Data to be passed to view before rendering.
*
* @return array
*/
public function with()
{
return [
'someVar' => $this->sayHello(),
];
}
public function sayHello()
{
return 'Hello from Composer';
}
}
I have tried adding the view composer in the view config of Sage 10 by adding (without any luck)
'composers' => [
ComposersApplication::class,
],
Does anyone know where to 'register' these custom Composers? I have to note that PSR-4 is autoloading the classes correctly.
Edit
The Sage 10 repository can be found here: https://github.com/roots/sage
question from:
https://stackoverflow.com/questions/65902652/roots-sage-10-using-view-composers-outside-of-app-directory 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…