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.

Data Model Questions /

DataObject search problem


Reply


1544 Views

Avatar
NickJacobs

Community Member, 144 Posts

29 April 2010 at 7:28pm

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