Bug @ CController::MissingAction()

Hi @ all !

When I try to call the following action in ForumController :


http://localhost/forum/search

I get (When using public function missingAction() :


Fatal error: Call to a member function getId() on a non-object in C:\wamp\framework\web\CController.php on line 482

But the search page appears correctly when using public function ActionSearch() :

[center][/center]

I think Yii tries to define an undefined action or something similar.

what is the complete call stack?

I dont know how I can show the stack trace.

here is the line 482 of CController.php :


	public function getRoute()

	{

		return $this->getUniqueId().'/'.$this->getAction()->getId();

	}

The code you can use to reproduce this bug is :

@foobarController :


class FoobarController extends Controller


public function missingAction()

    {

    	$this->render('foobar');

    }

@views/foobar/foobar.php :


<?php

include(Yii::app()->getBasePath() . '/../foobar.php'); # into /protected/../ folder.

?>

The problem is semi-solved when the requested method ( ActionSearch_() ) exists like :


    public function missingAction($missingActionId)

    {

    	$this->setAction($this->createAction($missingActionId.'_'));

        $this->render('forum',array('page'=>$missingActionId));

    }

	

    public function ActionSearch_() {}

In this case, Yii will render the ‘forum’ view flawlessly.

The bug is here :

Yii tries to define a page title via CController::getPageTitle() and a route via CController::getRoute() in the case of a missingAction() context in :


	public function getRoute()

	{

		return $this->getUniqueId().'/'.$this->getAction()->getId(); // $this->getAction() is NULL when using missingAction();

	}


	public function getPageTitle()

	{

		if($this->_pageTitle!==null)

			return $this->_pageTitle;

		else

		{

			$name=ucfirst(basename($this->getId()));

			if($this->getAction()!==null && strcasecmp($this->getAction()->getId(),$this->defaultAction)) // $this->getAction() is NULL here too.



In other words : $this->render() into a missingAction() method doesn’t work.

@admin: Do you think this is a bug that have to be solved ?

PS: see the post before this.

How is getRoute() called? Is it in layout or in foobar? What is in foobar?

The getPageTitle() method doesn’t seem to have problem because it checks if the action exists or not.

I don’t call getRoute() or anything, I simply use this code :

The controller :


class MyController extends Controller

{

public function missingAction()

    {

		$this->render('foobar');

    }

}

The view ( protected/views/foobar/foobar.php ) :


<?php

echo 'foobar';

?>

Then, when I go to a missing action (example : http://localhost/my/missing_action/ ), I get this error :


Fatal error: Call to a member function getId() on a non-object in C:\wamp\framework\web\CController.php on line 482

Try it yourself.

This is caused by the CMenu in your layout which would call getRoute(). I fixed the problem in svn. Thanks.