diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md
index 54b6c53df6..0bfd34435f 100644
--- a/framework/CHANGELOG.md
+++ b/framework/CHANGELOG.md
@@ -3,7 +3,7 @@ Yii Framework 2 Change Log
2.0.14 under development
------------------------
-
+- Enh #15216: Added `yii\web\ErrorHandler::$traceLine` to allow opening file at line clicked in IDE (vladis84)
- Enh #14488: Added support for X-Forwarded-Host to `yii\web\Request`, fixed `getServerPort()` usage (si294r, samdark)
- Enh #13019: Support JSON in SchemaBuilderTrait (zhukovra, undefinedor)
- Enh #15047: `yii\db\Query::select()` and `yii\db\Query::addSelect()` now check for duplicate column names (wapmorgan)
diff --git a/framework/views/errorHandler/callStackItem.php b/framework/views/errorHandler/callStackItem.php
index 04f8c88eba..512181d8b0 100644
--- a/framework/views/errorHandler/callStackItem.php
+++ b/framework/views/errorHandler/callStackItem.php
@@ -34,12 +34,14 @@
= (int) ($i + 1) ?>
-
+ htmlEncode($lines[$i]);
+ echo (trim($lines[$i]) === '') ? " \n" : strtr($handler->traceLine, ['{file}' => $file, '{line}' => $i + 1, '{html}' => $handler->htmlEncode($lines[$i])]);
}
- ?>
+ ?>
+
diff --git a/framework/web/ErrorHandler.php b/framework/web/ErrorHandler.php
index dad929d01e..0d39714d21 100644
--- a/framework/web/ErrorHandler.php
+++ b/framework/web/ErrorHandler.php
@@ -70,6 +70,16 @@ class ErrorHandler extends \yii\base\ErrorHandler
*/
public $displayVars = ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION'];
+ /**
+ * @var string placeholders to be be substituted.
+ * The placeholders are {file}, {line} and {text} and the string should be as follows.
+ *
+ * `File: {file} - Line: {line} - Text: {text}`
+ *
+ * @example {html}
+ * @since 2.0.14
+ */
+ public $traceLine = '{html}';
/**
* Renders the exception.
diff --git a/tests/framework/web/ErrorHandlerTest.php b/tests/framework/web/ErrorHandlerTest.php
index 91b19405c6..63ef0def36 100644
--- a/tests/framework/web/ErrorHandlerTest.php
+++ b/tests/framework/web/ErrorHandlerTest.php
@@ -38,6 +38,17 @@ class ErrorHandlerTest extends TestCase
Message: This message is displayed to end user
Exception: yii\web\NotFoundHttpException', $out);
}
+
+ public function testRenderCallStackItem()
+ {
+ $handler = Yii::$app->getErrorHandler();
+ $handler->traceLine = '{html}';
+ $file = \yii\BaseYii::getAlias('@yii/web/Application.php');
+
+ $out = $handler->renderCallStackItem($file, 63, \yii\web\Application::className(), null, null, null);
+
+ $this->assertContains('', $out);
+ }
}
class ErrorHandler extends \yii\web\ErrorHandler