Reputation: 18273
I have a controller (Controller_Product) that extends Controller_Template. In the Controller_Product I have some actions (create, edit, etc.) where I need the template to be rendered, but some actions (ex. save, delete) have to return a json object, so I don't need the template to be rendered. How can I solve this problem?
I can set the $this->auto_render to FALSE in my save or delete action, but the template will be created in this case too, even if will be no rendered. I think this is not very elegant to load a template when I don't actually need it.
Any suggestions?
Upvotes: 0
Views: 2978
Reputation: 9650
Something along these lines perhaps:
public function before()
{
if (in_array($this->request->action(), array('save', 'delete')))
{
$this->auto_render = FALSE;
}
parent::before();
}
[edit]
A better approach might be to check for an ajax request:
public function before()
{
if ($this->request->is_ajax())
{
$this->auto_render = FALSE;
}
parent::before();
}
Upvotes: 5