Reputation: 47
I have created new controller in the project but I am getting Not Found (#404) error when I try to access it. I am using the following URL http://localhost/basic/web/index.php?r=users/index
here is the controller:
<?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]);
}
}
?>
and here is the model:
<?php
namespace app\models;
use yii\db\ActiveRecord;
class Users extends ActiveRecord{
}
?>
and here is the view:
<?php
foreach($users as $user){
echo $user->username."<br/>";
}
?>
Upvotes: 1
Views: 3521
Reputation: 1
In Case of Advance, The namespace app must be change to frontend in addition to the Basel.shoban comment. like this frontend\controllers.
Upvotes: 0
Reputation: 47
solved, the error accorded because "Controller" shouldn't start with capital letter in the namespace.
Upvotes: 3
Reputation: 430
Try to use http://localhost/basic/web/index.php?r=users/indexe , because i see that your indec function in controller is public function actionIndexe()
Upvotes: 0