Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

php - Roots Sage 10 using view Composers outside of app directory

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...