Issues Adding the Yaml Response Formatter in Chapter 4

Yii 2 App Dev Book Errors chapter 4 errors

In chapter 4 (around pages 97-99) we are shown how to create a new output formatter which will render the page in Yaml syntax, but it results in:

This webpage is not available (Chrome, with a console error of 'net::ERR_INVALID_RESPONSE')
File not found (Firefox)

This post is specific to the 'Web Application Development with Yii 2 and PHP' book

In the utilities/YamlResponseFormatter.php file we instruct it to use the class at:

use Symfony\Component\Yaml\Yaml;

However, checking the vendors folder, this is not the correct location of the class.
If the path was added verbatim then it would be:

 use Symfony\yaml\Symfony\yaml\Component\Yaml\Yaml;

But the same result comes from adding the path as:

use Symfony\yaml\Component\Yaml\Yaml;

Unfortunately at the moment that result for me is a blank page but I'm just happy not to see any errors :)

As with the previous post on the JSON formatter, if you haven't added the use line for the new YamlResponseFormatter class in the services controller then you will end up with the fatal error:

PHP Fatal Error – yii\base\ErrorException
Class 'app\controllers\YamlResponseFormatter' not found

At the top of the controllers/ServicesController.php file you need to add the following line so it knows where to find the new class:

use app\utilities\YamlResponseFormatter;

For now I'm assuming that the lack of actual output or file download as the book suggests is down to my local setup and I'm moving on.... Thinking about it now, maybe file not found was actually the correct response in this case :( (I'm siding with not as the path classes are correct now so I would expect another error in this case)

Blog Comments powered by Disqus.