Advanced 'action' technique

I just read about the advanced action technique in the documentation.

So I created a test file call TestAction.php under /protected/controllers/test/TestAction.php

And in the controller ‘TestController.php’ under /protected/controllers/ I inserted




<?php


class TestController extends Controller

{


	public function actions()

	{

		return array(

			'page'=>array(

				'class'=>'CViewAction',

			),

			'test'=>'application.controllers.test.TestAction',

		);

	}

}

The TestAction.php file looks like:




<?php

class TestAction extends CAction

{

    public function run()

    {

        echo "Test";

    }

}

If I call this action using index.php?r=test/test in the browser, I get the following error message:

Any thoughts on what I could be missing here?

check that you have protected/controllers/test/TestAction.php

If the file is there… check for proper case of the file ie. TestAction.php… and the file and parent folder permissions

Thanks mdomba. It was indeed a problem with the folder’s permissions. Now it is working just fine :)

Now, how could I combine these two things:

With the help of this topic I created a method in my controller.

With mdomba’s help I managed to put the actions, which I used to have in my controller, into a file in a new folder.

Since the method still remains inside the controller what would be the appropriate way to call this method from inside the actions which is in the new folder? I believe $this is not an option anymore.

I would try $this->controller.

/Tommy

Hi Tommy,

I tried $this->TestController->getSiteModel(); but had no luck.

However, if I use TestController::getSiteModel(); it works.

Unfortunately I get the following error message now:

Any thoughts on how I could solve this problem?

You should try $this->controller->getSiteModel().

/Tommy

Thanks a lot Tommy!

This did the trick!! :)