views:

304

answers:

1

I've made an API controller with some actions to spit out JSON for my app and I've turned off the layout and view renderer in its init() method so I've got no view scripts for this controller.

I'm trying to use my apiController::treeAction elsewhere in the app via an actionHelper to output some JSON inline. I can access the action directly via /api/tree/id/1 which shows me the JSON data. But when I try and fetch from another controller with

$this->view->action('tree', 'api', null, array('id'=>$id))

I get an exception

Message: script 'api/tree.phtml' not found in path ([...]\application\views\scripts\)

It's right, that file doesn't exist, but I don't need it to. What am I doing wrong?

+1  A: 

You may want to look at the Action Helper Context Switch.

You can specify an action context of 'json' for this action and then it will automatically handle disabling the layout and view script rendering.

Noah Goodrich