Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__call method not get executed when try to call non existent function in yii controller?

Tags:

php

yii

<?php
class ReportsController extends CController
{
    public function __call($name,$argument)
    {
        echo "test";
    }

}
?>

This is my Yii controller class and when calling index.php?r=reports/test URL it has to call the __call method as test method is not exists but it gives error The system is unable to find the requested action test error.

like image 819
Ganesh Ghalame Avatar asked Oct 12 '12 05:10

Ganesh Ghalame


2 Answers

Implement missingAction method in your controller,

As said @xdazz, it checks if method exists and if not it calls missingAction method.

//This method is invoked when the controller cannot find the requested action.

public function missingAction($actionID)
{
    // Your code here
}
like image 102
SuVeRa Avatar answered Sep 30 '22 03:09

SuVeRa


This is depending on the implement of the framework.

For example, if the framework implement the code like:

If (!method_exists($controller, $action)) {
  throw new Exception("The system is unable to find the requested action $action");
}
like image 32
xdazz Avatar answered Sep 30 '22 03:09

xdazz