2010-09-03 22 views
1

J'ai développé une application gateau php.Comment implémenter la recherche au troisième niveau en utilisant un comportement confinable

Dans ce il y a des tables comme des étudiants, des stages, des lots, des entreprises

Dans le tableau des placements il y a student_id, company_id et table étudiants il y a colonne BATCH_ID.

Dans la page d'index des emplacements, j'ai appliqué jq grid. Voici la capture d'écran. alt text

Je souhaite effectuer des recherches sur les étudiants, les entreprises et les lots. Pour cela, j'ai utilisé un comportement confinable dans la fonction d'index du contrôleur de placements.

  if($this->params['url']['_search'] == 'true') /* For Searching*/ 
     { 
      //pr($this->params); 

      $searchconditions = array(); 

      if(isset($this->params['url']['studentname']) && !empty($this->params['url']['studentname'])) 
      { 
       array_push(&$searchconditions, array('Student.fullname LIKE' => $this->params['url']['studentname'] . '%')); 
      } 
      if(isset($this->params['url']['companyname']) && !empty($this->params['url']['companyname'])) 
      { 
       array_push(&$searchconditions, array('Company.name LIKE' => $this->params['url']['companyname'] . '%')); 
      } 
      if(isset($this->params['url']['batchname']) && !empty($this->params['url']['batchname'])) 
      { 
       array_push(&$searchconditions, array('Batch.name LIKE' => $this->params['url']['batchname'] . '%')); 
      } 

      $result = $this->Placement->find('all', array(
       'fields' => array('id','student_id','company_id'), 
       'contain' => array(
        'Student' => array(
         'fields' => array('id','fullname','batch_id'), 
         'Batch' => array(
          'fields'=> array('id','name') 
         )  
        ), 
        'Company' => array(
         'fields' => array('id','name') 
        ) 
       ), 
       'conditions' => $searchconditions, 
       'order' => $sort_range, 
       'limit' => $limit_range 
      )); 
     } 
     else /* Default display*/ 
     { 
      $result = $this->Placement->find('all', array(
       'fields' => array('id','student_id','company_id'), 
       'contain' => array(
        'Student' => array(
         'fields' => array('id','fullname','batch_id'), 
         'Batch' => array(
          'fields'=> array('id','name') 
         )  
        ), 
        'Company' => array(
         'fields' => array('id','name') 
        ) 
       ), 
       'order' => $sort_range, 
       'limit' => $limit_range 
      )); 
     } 

La grille est remplie avec le nom de l'étudiant, le nom de l'entreprise et le nom du lot (le cas échéant). Recherche travaille aussi bien dans le cas où je cherchai par nom de l'étudiant & nom de la société, mais quand j'ai essayé de recherche par nom de lot je reçois l'erreur suivante:

Warning (512): SQL Error: 1054: Unknown column 'Batch.name' in 'where clause' [APP\vendors\cakephp\cake\libs\model\datasources\dbo_source.php, line 681] 

Query: SELECT `Placement`.`id`, `Placement`.`student_id`, `Placement`.`company_id`, `Student`.`id`, `Student`.`fullname`, `Student`.`batch_id`, `Company`.`id`, `Company`.`name` FROM `placements` AS `Placement` LEFT JOIN `students` AS `Student` ON (`Placement`.`student_id` = `Student`.`id`) LEFT JOIN `companies` AS `Company` ON (`Placement`.`company_id` = `Company`.`id`) WHERE `Batch`.`name` LIKE 'df%' ORDER BY `Placement`.`id` asc LIMIT 0,10 

Je pense que la relation entre lots n'est pas étudiant & travaille comme peut être vu à partir de la requête. Je ne parviens pas à comprendre pourquoi il se comporte en tant que tel.

S'il vous plaît aidez-moi à ce sujet.

Merci

Répondre

1

Le comportement maîtrisable ne fait pas une jointure, mais fait des requêtes distinctes pour chaque table. Utilisez le linkable plugin. C'est un excellent plugin. Il va certainement résoudre votre problème.

Réponse posée par Monsieur sytzeloor sur cakeqs. En utilisant ce plugin, vous pourrez facilement effectuer une opération de recherche dans le modèle de placement en fonction d'un nom de lot. Faites comme ceci dans votre contrôleur de placement et je parie que vous obtiendrez des résultats comme prévu.

$result = $this->Placement->find('all', array(
       'fields' => array('id','student_id','company_id'), 
       'link' => array(
        'Student' => array(
         'Batch' 
        ), 
        'Company' 
       ), 
       'conditions' => $searchconditions, 
       'order' => $sort_range, 
       'limit' => $limit_range 
      )); 
+0

Merci gaurav pour votre aide, il a résolu mon problème. –

+0

@Pankaj Khurana: vous êtes les bienvenus –