Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » CustomSearchForm snippet

Discuss all other Modules here.

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

Page: 1 2 3 4 5 6
Go to End
Author Topic: 9954 Views
  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: CustomSearchForm snippet Link to this post

    awesome. best results I've had from any search situation so far with silverstripe. onbeforewrite and creating a master collection in metadescription was a great idea. Simple but something I didn't think about. I have it working with a few different dataobjects now and multiple page subclasses. Exactly what I wanted. Thanks again.

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: CustomSearchForm snippet Link to this post

    I have one other question which will hopefuly be relevant to other people as it seems a pretty common situation. What happens when the GlossaryTerm is connected to another dataobject through a hasmany or many_many connection? Supposing a GlossaryTerm could have many references, in searchcontext and modeladmin I could add into searchable fields 'MyReference.Title' but with setup it crashes the sql and I get an error such as

    [User Error] Couldn't run query: ALTER TABLE "GlossaryTerm" DROP INDEX "SearchFields", ADD fulltext "SearchFields" (.....,....,....,...) Key column 'MyReferences' doesn't exist in table

    Is there a fairly simple way to get around this? Thanks again

  • lanks
    Avatar
    Community Member
    61 Posts

    Re: CustomSearchForm snippet Link to this post

    I am getting a blank page when trying to use this search form.... All I want to do is search one type of DataObject. I have implemented the form in the Page.php. I tried using a simple control in the page template to display results.... is this the right way ?
    <% if results %>
    <% control results %>
    $Property
    <% end_control %>
    <% end_if %>

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: CustomSearchForm snippet Link to this post

    Hi lanks

    Sorry only just noticed your post. you still working on this by any chance?

    If so it sounds like you are missing the template Page_results.ss. I don't see why I shouldn't work in Page.ss though as long as nested correctly.

    Heres the markup I have showing my results

    <% if Results %>
        <ul id="SearchResults">
        <% control Results %>
        <li>

        <% if MenuTitle %>
        <h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>

        <% else %>
        <h3><a class="searchResultHeader" href="$Link">$Title</a></h3>

        <% end_if %>
              <% if Content %>
           $Content.FirstParagraph(html)

              <% end_if %>

        <a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>

        </li>

        <% end_control %>
        </ul>
        <% else %>
        <p>
                <%-- Example of a translatable string (see http://doc.silverstripe.org/i18n) --%>
                <% _t("Page_results.ss.NORESULTS", "Sorry, your search query did not return any results.") %>
                <%-- By the way, template comments marked like this will be excluded from the HTML output --%>
             </p>
        <% end_if %>

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: CustomSearchForm snippet Link to this post

    Hello, Aram, a question for you:
    what exactly changed with this custom search? I ask it cause none of the links work now, but search works fine.

    To clerify, I had a LOTDPage where i displayer LOTDs - link of the day.
    I made a few functions, one of them being a delete function, the other is a frontend edit function.
    Both of them were controlled via link. Also, one of LOTDs was leading to my homepage.
    In any case, non of the links works, even for my homepage, and every time i run dev/build it creates a new page called Home. I guess since it is missing that none of my links work and something is messed up. I just wanna know how to fix all that. If you need further clarification I have added all of my files in example, somwhat like what you posted in your original post.

    Plz help!

    Attached Files
  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: CustomSearchForm snippet Link to this post

    Hi Mac

    Not sure sure about the homepage issue, sounds like you don't have one in place though. Silverstripe forces you to always have a homepage I think so even if the navigation name isn't home the url has to be home.

    On LOTD.php your link function doesn't do anything

    public function Link() {
    return DataObject::get_one("LOTDPage")->Link() ."#term".$this->ID;
    }


    it's calling your LOTDPage then just telling it the term ID but not telling it what to do with it. As a start you need to change in LOTDPage

    static $allowed_actions = array(
          'ShowTerm'
       );


    to

    static $allowed_actions = array(
          'ShowLOTD'
       );

    and the link function in LOTD to

    public function Link()
    {
          if($Page = DataObject::get_one("LOTDPage "))
          return $Page->Link() ."ShowLOTD /".$this->ID;
    }

    I haven't tested any of this but thats what it looks like on first glance

  • wilsonStaff
    Avatar
    Community Member
    142 Posts

    Re: CustomSearchForm snippet Link to this post

    Hi to all, i am trying to get this thing straightened out: Getting my customs textfields to become searcheabled. I like the simplicity of populating the $Metatags or $Description with text taken from my customs textfields. As those ($Metatags and $Description) are searcheabled, this does the trick. But HOW and WHERE to do that?

    I am no PHP expert, but in plain text or back to my ActionScipt 3 days, that would be like this:

    $Metatags.text = $Nom.text + $Prenom.text + $Entreprise.text

    Where $Nom, $Prenom, $Entreprise are my custom textfields.

    I KNOW THIS ISNT IT, but that what i want!

    - - -

    Any help appreciated.

    Thanks!

  • vancouverWill
    Avatar
    Community Member
    121 Posts

    Re: CustomSearchForm snippet Link to this post

    I wanted to add in my information from some textfields columnOne and ColumnTwo so i used below. You might want to read up a little on PHP classes and objects it will make it a lot easier to understand.

    function onBeforeWrite() {
          parent::onBeforeWrite ();
          if (strlen(trim($this->record['MetaDescription']))<1){
          
          $this->record['MetaDescription']=$this->Content.' '.$this->ColumnOne.' '.$this->ColumnTwo.' '.$this->ColumnThree.' '.$this->BottomContent;
          }
       }


    UPDATED ABOVE

    9954 Views
Page: 1 2 3 4 5 6
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.