Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObject search problem

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

Page: 1
Go to End
Author Topic: 1515 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    DataObject search problem Link to this post

    HI, I have a search form which I just cannot get working....I keep getting a "Missing argument 1 for Page_Controller::results()" error. I'm hoping someone can see where I'm going wrong:

    In my dataobject (Collection) I have:

    static $db = array (
          'Fulltext' => 'Text',
          'Family' => 'Text',      
          'Genus' => 'Text',
          'Hybrid' => 'Text',
          'Species' => 'Text',      
          'Infraspecific' => 'Text',
          'Cultivar' => 'Text',
          'CultivarGroup' => 'Text',
          'Synonym' => 'Text',
          'CommonName' => 'Text',
          'Continent' => 'Text',
          'GeoRegion' => 'Text',
          'Herbarium' => 'Boolean',
          'IUCNCode' => 'Text',
          'Fieldx1' => 'Text',
          'Var' => 'Text'
       );

    static $keywords_search_fields = array (
          'Family','Genus','Hybrid','Species','CommonName'
       );

    the search form I have setup like so:

    public function CollectionSearchForm()
       {
          $f = new Form(
             $this,
             "CollectionSearchForm",
             new FieldSet(
                $genus = new DropdownField('Genus','Genus', DataObject::get('Collection')->toDropdownMap('Genus','Genus')),
                $herbarium = new CheckboxField('Herbarium','Herbarium specimens only'),
                
                $keywords = new TextField('Keywords')
             ),
             new FieldSet(
                new FormAction('doCollectionSearch','Search')
             )
          );
          $f->setFormMethod('get');
          $genus->setEmptyString('-- All --');
          if(isset($_REQUEST['Genus'])) $genus->setValue(urldecode($_REQUEST['Genus']));
          if(isset($_REQUEST['Herbarium'])) $herbarium->setValue(urldecode($_REQUEST['Herbarium']));   
          if(isset($_REQUEST['Keywords'])) $keywords->setValue(urldecode($_REQUEST['Keywords']));
          return $f;
       }
       
       public function doCollectionSearch($data, $form)
       {
          $filters = array();
          if(isset($data['Keywords']) && !empty($data['Keywords'])) {
             $k = $data['Keywords'];
             $keywords = array();
             foreach(Collection::$keywords_search_fields as $field)
                $keywords[] = $field . " LIKE '%{$k}%'";
             $keywords_clause = implode(" OR ", $keywords);
             $filters[] = "(".$keywords_clause.")";
          }
          if(isset($data['Genus']) && !empty($data['Genus'])) {
             $g = $data['Genus'];
             $filters[] = "Genus = '{$g}'";
          }
          
          if(isset($data['Herbarium']) && !empty($data['Herbarium'])) {
             $h = $data['Herbarium'];
             $filters[] = "Herbarium = {$h}";
          }      
          
          $where = implode(" AND ", $filters);
          
          if(!isset($_REQUEST['start'])) $_REQUEST['start'] = 0;
          $limit = $_REQUEST['start'].",10";
          return $this->customise(array(
             'Collections' => DataObject::get("Collection", $where, null, null, $limit)
          ))->renderWith(array('Collection_results','Page'));
       }
       

    Anyone see obvious errors???
    thanks

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