找不到 yii2 (#404)
yii2 Not Found (#404)
我已经在项目中创建了新的控制器,但是当我尝试访问它时出现未找到 (#404) 错误。
我正在使用以下 URL
http://localhost/basic/web/index.php?r=users/index
这里是控制器:
<?php
namespace app\Controllers;
use yii\web\Controller;
use app\models\Users;
class UsersController extends Controller
{
public function actionIndex()
{
$users= Users::find()->all();
return $this->render('index',['users'=>$users]);
}
}
?>
这是模型:
<?php
namespace app\models;
use yii\db\ActiveRecord;
class Users extends ActiveRecord{
}
?>
视图如下:
<?php
foreach($users as $user){
echo $user->username."<br/>";
}
?>
尝试使用 http://localhost/basic/web/index.php?r=users/indexe ,因为我看到你在控制器中的 indec 函数是 public function actionIndexe()
已解决,由于 "Controller" 在命名空间中不应以大写字母开头而出现的错误。
在 Advance 的情况下,除了 Basel.shoban 注释之外,命名空间应用程序必须更改为前端。像这样 frontend\controllers.
我已经在项目中创建了新的控制器,但是当我尝试访问它时出现未找到 (#404) 错误。 我正在使用以下 URL http://localhost/basic/web/index.php?r=users/index
这里是控制器:
<?php
namespace app\Controllers;
use yii\web\Controller;
use app\models\Users;
class UsersController extends Controller
{
public function actionIndex()
{
$users= Users::find()->all();
return $this->render('index',['users'=>$users]);
}
}
?>
这是模型:
<?php
namespace app\models;
use yii\db\ActiveRecord;
class Users extends ActiveRecord{
}
?>
视图如下:
<?php
foreach($users as $user){
echo $user->username."<br/>";
}
?>
尝试使用 http://localhost/basic/web/index.php?r=users/indexe ,因为我看到你在控制器中的 indec 函数是 public function actionIndexe()
已解决,由于 "Controller" 在命名空间中不应以大写字母开头而出现的错误。
在 Advance 的情况下,除了 Basel.shoban 注释之外,命名空间应用程序必须更改为前端。像这样 frontend\controllers.