Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Setting 'main' Title from within controller

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: 1690 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    Setting 'main' Title from within controller Link to this post

    Hi guys,

    I'm having this function in my TipHolder_Controller (extends Page_Controller):

    function edit()
    {
    $output = array(
             "EditForm" => $this->EditForm,
             "Title" => "Wijzig Je Locatie"
             );
       return $this->customise($output)->renderWith(array('EditForm', 'Page'));
    }

    When doing that I get this error:

    FATAL ERROR: ViewableData_Customised::obj() 'Title' was requested from the array data as an object but it's not an object. I can't cast it.

    I want to change the normal page title from within that action...
    I'm actually not seeing the difference (yet) with what there's going on in the search tutorial - results method, where it's not working for me either
    see http://doc.silverstripe.com/doku.php?id=tutorial:4-site-search#showing_the_results

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Setting 'main' Title from within controller Link to this post

    Nobody?

    This even seems to crash the 'lostpassword' function, that also seems to set the title..?

  • blueskies
    Avatar
    Community Member
    42 Posts

    Re: Setting 'main' Title from within controller Link to this post

    Hi dio5,

    I just ran into the same problem and have a solution.

    My situation was as follows: Because I needed to use the LimitWordCount method on the title of the page, I had to cast it to a text (default it is a varchar and LimitWordCount is not available on that).

    So I added:

    static $casting = array(
        "Title" => "Text",
       );

    When I subsequently implemented a search (search tutorial) and added this:

    $data = array(
             'Results' => $form->getResults(),
             'Query' => $form->getSearchQuery(),
             'Title' => "Search results"
          );

    I got the "I can't cast" error because now there wasn't an object to cast, but there was only a string.

    I solved it by changing the Title in the $data array:

    $obj = new Varchar("Title"); // Or set this to Text/etc...
    $obj->setValue("This is my page title");
          
    $data = array(
       'Results' => $form->getResults(),
       'Query' => $form->getSearchQuery(),
       'Title' => $obj
    );

    Now the title is an object and all code works happily ever after...

    1690 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.