PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] Create a new Controller manually and face with "View not Found" error in Yii

 February 16, 2022     yii, yii2, yii2-basic-app     No comments   

Issue

I use basic template of yii, i create a new controller manually in Controllers Folder and name it CountryController.php and put bellow codes in it.

<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;

class CountryController extends Controller
{
    public function actionIndex()
    {
        return $this->render('index');
    }
}

But when i type http://localhost/sites/basic/web/index.php?r=country%2Findex in browser i get following Exception:

View not Found yii\base\ViewNotFoundException

This is image of the error

On the other side when i type http://localhost/sites/basic/web/index.php?r=site%2Findexin the browser it renders index view correctly.

Why this happen? can i create a Controller manually? How?


Solution

The error message is not saying it can't find the page, just that it can't find the view file. Along with your controller, you should also have created a view file app\views\country\index.php This is the file you are referring to when you call `$this->render('index').



Answered By - Joe Miller
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing