Roots Discourse

Sage - SoberWp Controller - {! App::title() !} in blade view is not working

blade
sage9

#1

I have just installed the latest version of sage that uses the soberwp controller package, after running composer install and yarn as instructed in docs I get this error on the site home page:

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App' not found ....

ErrorException: Class 'App' not found (View: /srv/www/xxxxxxx.org/current/web/app/themes/sage-controller/resources/views/partials/page-header.blade.php) (View: /srv/www/xxxxxxx.org/current/web/app/themes/sage-controller/resources/views/partials/page-header.blade.php) in /srv/www/xxxxxxx.org/current/web/app/uploads/cache/b86c51c4f6669655bff05894c46da3bddd3b03b4.php on line 2

I thought the controllers weren’t loading but in vendor/composer/autoload_psr4.php this line exists:

'App\\' => array($baseDir . '/app'),

maybe the contollers/helpers are not accessible to the blade views

any help would be appreciated, thanks


#2

btw i am using the dev-master branch of sage, I think this is the same as 9.0.0-beta.4


#3

I have similar issue. It seems like by default theme does not work, which is quite surprising knowing how good roots guys and how long this issue now exists.

I am using trellis too which is even more annoying.


#4

This shouldn’t be an issue…


#5

+1 Im getting exactly the same bug.


#6

Is this a fresh Sage install? How did you create it? Did you use composer to create it, or did you clone from GitHub?

Are you using Trellis and/or Bedrock?

If you remove the App:title() call does it work? Or do you get a different error?


#7

Hi @MWDelaney

Yep fresh install. Composer was used.

This happens for any static method called on the App controller


#8

What’s your environment like? Are you using Trellis? More specifically, what version of PHP are you using?


#9

Not using Trellis. We use Laravel’s Homestead enviroment and php deployer to deploy which works with all our other sites. PHP 7.1 is being used.


#10

Hmm. I’m short on ideas. Is it possible to test the theme in a different environment to rule out the environment as the problem? Either a shared host somewhere, or a quick and dirty Trellis setup?


#11

It does seem like an enviroment issue… although other Sage sites are running and using static methods just fine in this exact enviroment.


#12

It’s an environment difference, probably case-sensitivity — what works on a case-insensitive Mac local might not work on a case sensitive linux server. Check the error logs and look at file names in app/controller.

Issues with case were fixed in Sober Controller 2.0.1


#13

I can confirm that this is still a valid bug. I downloaded the Sage theme and installed it out of the box. I am getting this error:


Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App' not found in /web/htdocs3/xxxxxxxx/home/www/wp-content/uploads/sites/3/cache/ae3e6bb8ed1b2e659d526c1845c364f3d3d44fcd.php:2 Stack trace: #0 /web/htdocs3/xxxxxxxx/home/www/wp-content/themes/d3sage/vendor/illuminate/view/Engines/PhpEngine.php(43): include() #1 /web/htdocs3/xxxxxxxx/home/www/wp-content/themes/d3sage/vendor/illuminate/view/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/web/htdocs3/di...', Array) #2 /web/htdocs3/xxxxxxxx/home/www/wp-content/themes/d3sage/vendor/illuminate/view/View.php(142): Illuminate\View\Engines\CompilerEngine->get('/web/htdocs3/di...', Array) #3 /web/htdocs3/xxxxxxxx/home/www/wp-content/themes/d3sage/vendor/illuminate/view/View.php(125): Illuminate\View\View->getContents() #4 /web/htdocs3/xxxxxxxx/home/www/wp-content/themes/d3sage/vendor/illuminate/view/View.php(90): Illuminate\View\View->renderContents() #5 /web/htdocs3/xxxxxxxx/home/www/w in /web/htdocs3/xxxxxxxx/home/www/wp-content/uploads/sites/3/cache/ae3e6bb8ed1b2e659d526c1845c364f3d3d44fcd.php on line 2

I tried to gather as much information as possible. Could you please help me with this? The only solution I can come up with is to remove {!! App::title() !!} from this file: resources\views\partials\page-header.blade.php (line 2). Then it works. But it would be better if the theme worked out of the box even on my server configuration which I have no control over - it’s set up by the hosting provider.

This is the server settings as provided by my hosting provider:

Server

  • Linux CentOS
  • Apache 2.2
  • Server Side Includes - SSI

PHP

  • version 7.1.3
  • system: Linux webxc03s07 2.6.32-696.18.7.el6.x86_64 #1 SMP Thu Jan 4 17:31:22 UTC 2018 x86_64
  • configuration: normal_default_71
  • execution_time: 90 sec
  • memory_limit: 128MB
  • upload_limit: 32MB
  • ini_set
  • safe_mode OFF
  • register_globals OFF
  • extensions: gd2, ImageMagick, Zip

Server supports the following: HTML, PHP, Perl, Ruby, Python, SHTML and Flash/Shockwave.


#14
  • What version of Sage are you using? How did you install it?
  • Did you run composer install in your theme directory, and include the generated vendor folder when uploading to your sever?
  • Do other variables provided by Controller work as intended in your templates?

#15
  • Sage version 9.0.1
  • Yes, I ran composer install locally, then I uploaded the vendor folder to hosting provider via FTP
  • I didn’t notice any other changes / problems. I had to modify paths in these files manually upon deployment:
  1. config\assets.php
  2. config\theme.php
  3. config\view.php
  4. resources\functions.php and also I had to move this file out of the resources folder and put it directly to the theme folder on the server to make the theme work, and modify the paths in the file to autoload.php

#16

What were the paths you had to modify? How does the organization of your production theme vary from your development theme?


#17

Here are the paths I had to modify. Notice that my theme is called d3sage.

Plus like I said I moved the functions.php file from resources to the root of my theme folder on the production server to make the theme work.


#18

You may have broken composer autoloading (which is how Sage finds stuff in the App namespace) by changing the makeup of your theme. I would recommend modifying your local development environment to match your remote environment exactly, running composer install again, and re-uploading the theme. I’m curious why you needed move things around, though. I’ve never had trouble with that when adding a theme via FTP.


#19

What do you mean by that? I just installed the theme locally with no further changes and wanted to deploy it to my production server to test it if it works out of the box.

I was also confused by the documentation which doesn’t mention a word about what should be copied to the server via FTP. At first I thought it was only the contents of the dist folder but then realized it only contained the assets. Maybe an update of the documentation (how to deploy via FTP) would make this whole process easier.

I tried running composer install locally (since I can’t run it on the production server). The paths were OK for local development but wrong for the production so that’s why I had to modify them manually. The question is why?

Also we got distracted from the original issue – why using the {!! App::title() !!} in resources\views\partials\page-header.blade.php breaks the theme and shows the error I posted originally. Any ideas how to solve that issue?


#20

As with any WordPress theme, everything should work if you copy the entire directory. If you want, you can skip node_modules, .git, and app/assets.

“Why” depends on the configuration of your local and production environments. Because you haven’t provided whatever the errors were that prompted you to change them, I can’t guess what the cause might be.

Paths are very pertinent to this issue. Look at the error you posted:

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App' not found in [...]

This means that PHP is unable to find the class App. It knows (or should know) where to find App because of this section of your theme’s composer.json:

"autoload": {
    "psr-4": {
      "App\\": "app/"
    }
  },

Essentially, that says “If anything asks for the App class, you can find it in app/.” When you run composer install (or update or dump-autoload) Composer will generate an autoloader based on that, which will then be used to load classes when they are requested. If you want to see what it generates, you can look in vendor/composer/autoload_psr4.php. If you run composer install and then move files around in your theme, these paths may no longer be correct. I don’t fully understand the changes you’ve made to your theme (it looks like you’ve put some of it in a subfolder of itself, with the same name as the theme itself?), so I’m not sure if that’s the problem.

In general, though, it’s a very good practice to make sure that your local development environment matches your production environment as exactly as possible, include the file organization of your theme.