As I see if we want to create an instance of the model (for example, with a name Post), we just need to call:
$post = new Post();
Now I also want to create an instance Controller(for example, with the name Postand php file for this controller with the name PostController.php). Therefore, I use this code:
$postController = new PostController();
However, when I run this code, I get an error.
I did a few searches and found that the following should be done to create the instance:
$postController = Yii::app()->createController('post/index');
It is working correctly. But I'm still wondering why the first approach does not work?
source
share