Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Calling an action on init()


3 Posts   2090 Views


3 February 2010 at 6:56pm (Last edited: 3 February 2010 6:57pm), Community Member, 105 Posts

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()
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?


3 February 2010 at 7:15pm Community Member, 712 Posts

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.


3 February 2010 at 7:21pm Community Member, 105 Posts

Hey thanks Hamish works like a charm!

Kind of funny I was just reading [url=]Controllers[/url] that mentions that but it did not occur to me to actually try it :)