Hello all , 

I need some help on autocomplete,
I want to fetch merchant names from database.
 Here is my code. 

controller

<?php          
  class MerchantsController extends AppController {             

   var $name = 'Merchants';       
  var $uses = 
array('Customer','Parameter','Merchant','Merchantcard','Merchantcustomfield'); 
  
  var $helpers =  array('Html','Form','Ajax','Javascript');      
  var $components = array('Session','Auth','RequestHandler');             

      function index()         {                 
         $this->set('title_for_layout', 'Select Merchant: Loyalty card'); 
      
                               $this->set('merchant',  
$this->Merchant->find('all'));          
                      }         

                function autoComplete() {           
                 $this->set('merchants', $this->Merchant->find('all', 
array(                     'conditions' => array(                     
'Merchant.name LIKE' => '%a%'                     )                     
)));      
        
                  $this->layout = 'ajax';              
               }                

                 function beforeFilter() {                   
$this->Auth->allow('*');         }          } 

model


    class Merchant extends AppModel {
        
          var $name = 'Merchant';
    
    }


views
index.ctp

    <?php echo $form->create('Merchant', array('url' => 
'/merchants/index')); ?> 
    <?php echo $ajax->autoComplete('Merchant.name', 
'/merchants/autoComplete')?>
     <?php echo $form->end('find')?>

autocomplete.ctp
     <ul>     <?php foreach($merchants as $merchant): ?> 
    <li><?php echo $merchant['Merchant']['name']; ?></li>  
   <?php endforeach; ?>     </ul> 


Is there anything wrong in this code , following all steps from cake 
documentation , i am using cakephp version 1.3

Thanks in advance,
Mangesh Sathe


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to