Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » What's the correct way to publish a view after a form post.

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 802 Views
  • adiwidjaja
    Avatar
    Community Member
    14 Posts

    What's the correct way to publish a view after a form post. Link to this post

    Hi,

    I'm wondering what the correct method ist to publish a different view after a form post. My use case: I want to filter a view via a form. I currently have this code:

    function FilterForm() {

    //...

          $actions = new FieldSet(
             new FormAction( "filter", _t('UserDefinedForm.FILTER', 'Filtern') )
          );

    //...

    return new Form( $this, "FilterForm", $fields, $actions );
    }

       function filter($data, $form) {
          $ids = $this->someComplicatedFiltering($data);
          $_GET["ids"] = $ids;
          return Director::direct($this->data()->URLSegment."//select");
    }

    function select() {
    return array("FilteredIds" => $_GET["ids"]);
    }

    It works, but I don't think it's nice because the Director starts from the very beginning.

    I tried to make this work:

    $this->pushCurrent();

    $controller = new ModelAsController();

    $request = new HTTPRequest("GET", $this->data()->URLSegment.'//preview', $request->getVars(), $request->postVars());
    $request->match('$URLSegment//$Action/$ID/$OtherID');

    $result = $controller->handleRequest($request);

    $this->popCurrent();
    return $result->getBody();

    But this didn't work, it always showed me the default view of the object. I traced this to a code segment, where the request url (object_urlsegment/view) is "pushed" so it's object_urlsegment/object_urlsegment/view (I don't understand the use case of that).

    So finally my question: What is the correct method to do this? There are two versions of this use case: Fetch a different view of the current object or fetch a view of a different object.

    Thanks for your clarification,

    Cheers,

    Andy

    802 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.