craftcms / anchors

Add anchor links to headings in your Craft CMS website content.
MIT License
48 stars 7 forks source link

"Headers already sent" error #10

Closed ryanwhitney closed 4 years ago

ryanwhitney commented 4 years ago

When I create an anchors.php config file, my template renders errors with the source of the anchors.php file at the top. This happens regardless, whether or not I'm using the anchors filter in my template, and also kills the admin area of the site.

Here's the entire output:

`return [ 'anchorClass' => 'heading', ]; An Error occurred while handling another error: yii\web\HeadersAlreadySentException: Headers already sent in /Users/rwhitney/crafttest/config/anchors.php on line 1. in /Users/rwhitney/crafttest/vendor/yiisoft/yii2/web/Response.php:366 Stack trace:

0 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/web/Response.php(339): yii\web\Response->sendHeaders()

1 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()

2 /Users/rwhitney/crafttest/vendor/craftcms/cms/src/web/ErrorHandler.php(128): yii\web\ErrorHandler->renderException(Object(yii\base\ErrorException))

3 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/base/ErrorHandler.php(123): craft\web\ErrorHandler->renderException(Object(yii\base\ErrorException))

4 /Users/rwhitney/crafttest/vendor/craftcms/cms/src/web/ErrorHandler.php(61): yii\base\ErrorHandler->handleException(Object(yii\base\ErrorException))

5 [internal function]: craft\web\ErrorHandler->handleException(Object(yii\base\ErrorException))

6 {main}

Previous exception: yii\base\ErrorException: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/rwhitney/crafttest/config/anchors.php:1) in /Users/rwhitney/crafttest/vendor/yiisoft/yii2/web/Session.php:137 Stack trace:

0 /Users/rwhitney/crafttest/vendor/craftcms/cms/src/web/ErrorHandler.php(74): yii\base\ErrorHandler->handleError(2, 'session_start()...', '/Users/rwhitney...', 137)

1 [internal function]: craft\web\ErrorHandler->handleError(2, 'session_start()...', '/Users/rwhitney...', 137, Array)

2 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/web/Session.php(137): session_start()

3 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/web/Session.php(630): yii\web\Session->open()

4 /Users/rwhitney/crafttest/vendor/craftcms/cms/src/web/Application.php(387): yii\web\Session->get('enableDebugTool...')

5 /Users/rwhitney/crafttest/vendor/craftcms/cms/src/web/Application.php(104): craft\web\Application->debugBootstrap()

6 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()

7 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->__construct(Array)

8 /Users/rwhitney/crafttest/vendor/craftcms/cms/src/web/Application.php(91): yii\base\Application->__construct(Array)

9 [internal function]: craft\web\Application->__construct(Array)

10 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/di/Container.php(400): ReflectionClass->newInstanceArgs(Array)

11 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/di/Container.php(159): yii\di\Container->build('craft\web\Appli...', Array, Array)

12 /Users/rwhitney/crafttest/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\web\Appli...', Array, Array)

13 /Users/rwhitney/crafttest/vendor/craftcms/cms/bootstrap/bootstrap.php(245): yii\BaseYii::createObject(Array)

14 /Users/rwhitney/crafttest/vendor/craftcms/cms/bootstrap/web.php(51): require('/Users/rwhitney...')

15 /Users/rwhitney/crafttest/web/index.php(20): require('/Users/rwhitney...')

16 {main}`

ryanwhitney commented 4 years ago

I, an idiot, forgot to put a <?php opening tag at the top of the file. 🙂