21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1346 Views |
-
Calling an action on init()

3 February 2010 at 6:56pm Last edited: 3 February 2010 6:57pm
I have a product site that basically uses search filters to display the products all good basically have it working you select some filters and press go and it will return the products great.
My question is I would like to call the action 'search' on the controller without posting the form so by default it will return all of the products until the user selects some filters and presses go.
class ProductPage_Controller extends Page_Controller {
...
public function init()
{
parent::init();
if(!isset($_POST)) {
return $this->search();
}
}public function search()
{
// do stuff return all results or results if $_POST filters set
return $this->customise($data)->renderWith(array('ProductPage', 'Page'));
}
}Can this be done or is there an easier way?
-
Re: Calling an action on init()

3 February 2010 at 7:15pm
index() is the default method - ie, when no other action is request, index is called.
So, instead of using init() (which is called on every action and is not supposed to return a response), move your method to index() and it should work as intended.
-
Re: Calling an action on init()

3 February 2010 at 7:21pm
Hey thanks Hamish works like a charm!
Kind of funny I was just reading Controllers that mentions that but it did not occur to me to actually try it
| 1346 Views | ||
|
Page:
1
|
Go to Top |


