最近我有网站开发了另一个人,是用yii2编写的,每当我尝试打开索引时,handlererror重定向到site / error.php,当通过actionIndex时没有找到该网站(查看) ,我是yii2的新手,我试图解决这个问题没有得到index.php
public function actionIndex()
{
// $this->layout = false;
return $this->render('index');
}
$ this的输出是:
app\controllers\SiteController Object
(
[layout] => site
[enableCsrfValidation] => 1
[actionParams] => Array
(
)
[id] => site
[module] => yii\web\Application Object
(
[defaultRoute] => site
[catchAll] =>
[controller] => app\controllers\SiteController Object
*RECURSION*
[_homeUrl:yii\web\Application:private] =>
[controllerNamespace] => app\controllers
[name] => My Application
[version] => 1.0
[charset] => UTF-8
[language] => en-US
[sourceLanguage] => en-US
[layout] => admin
[requestedRoute] =>
[requestedAction] => yii\base\InlineAction Object
(
[actionMethod] => actionIndex
[id] => index
[controller] => app\controllers\SiteController Object
*RECURSION*
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] =>
)
它要长得多,但我不能在这里粘贴所有内容。
我想这对某些路线或控制器来说一定是个问题,但我不知道问题是什么
答案 0 :(得分:0)
您的观点路径可能存在问题。请查看指南:Controller和View。
如您所见,有一些关于文件名和文件夹的约定。确保你有类似下面的例子:
档案:controller/MyAwesomeIdController.php
<?php
namespace app\controllers;
use yii\web\Controller;
class MyAwesomeIdController extends Controller
{
/**
* @return mixed
*/
public function actionIndex()
{
$myVar = 'value';
return $this->render('index', [
'myVar' => $myVar
]);
}
}
档案:views/my-awesome-id/index.php
<?php
/* @var $this yii\web\View */
/* @var $myVar string */
use yii\helpers\Html;
$this->title = $myVar;
?>
<div class="my-awesome-id-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vestibulum tristique diam, sed facilisis tortor ultricies vitae. Ut lectus leo, egestas sit amet luctus vel, luctus eu enim. Maecenas gravida egestas varius. Cras eu congue quam, in mattis enim. Aliquam nec augue nisi. Sed in tincidunt tellus, vel auctor urna. Donec ipsum tortor, pulvinar in luctus nec, tristique in metus. Ut dapibus velit ac mi lobortis finibus.
</p>
</div>