Hello everyone,
this issue ...
I have an autocomplete text field that displays the field
"codice" but i would assign the value "cod_mezzi".
I state that the table does not use conventional names.
These lines that I wrote.

model mean.php

<?php
class mean extends AppModel
{
 var $name = 'mean';
 var $useDbConfig = 'ufficial_intranet';
 var $useTable = 't_mezzi';
 var $primaryKey ='cod_mezzi';

var $hasMany = array(
                    'Reservation' => array(
                    'className' => 'Reservation',
                    'foreignKey' => 'mean_id',
                    'dependent' => false,
                    'conditions' => '',
                    'fields' => '',
                    'order' => '',
                    'limit' => '',
                    'offset' => '',
                    'exclusive' => '',
                    'finderQuery' => '',
                    'counterQuery' => ''
 )
 );
 }
 ?>
model reservation.php
<?php
class reservation extends AppModel {

var $name = 'reservation';

var $belongsTo = array(
                         'Place' => array(
                         'className' => 'Place',
                         'foreignKey' => 'place_id',
                         'conditions' => '',
                         'fields' => '',
                         'order' => ''
                         ),
                        'Mean' => array(
                        'className' => 'Mean',
                        'foreignKey' => 'mean_id',
                        'conditions' => '',
                        'fields' => '',
                        'order' => ''
 )
 );
 }
 ?>


means_controller.php


<?php
class MeansController extends AppController {

        var $name = 'Means';
        var $helpers = array('Html', 'Form', 'Ajax', 'Javascript');

.....
.....
 function autoComplete() {
        
            $means = $this->Mean->find('all', array(
                                'conditions' => array(
                                'Mean.codice LIKE' => '%' . 
$this->data['Mean']['codice'].'%'
                                ),
                                'fields' => array('cod_mezzi','codice')));

           $this->set(compact('means'));

            if(isset($this->params['requested'])) {
                 return $means;

            }
            $this->set('means', $means);
            $this->layout = 'ajax';
        }
.......
.......
?>

reservations_controller.php

<?php
class ReservationsController extends AppController {

        var $name = 'Reservations';
        var $helpers = array('Html', 'Form');
......
......
function add() {
                if (!empty($this->data)) {
                        $this->Reservation->create();
                        if ($this->Reservation->save($this->data)) {
                                $this->Session->setFlash(__('The Reservation 
has been saved', true));
                                $this->redirect(array('action'=>'index'));
                        } else {
                                $this->Session->setFlash(__('The Reservation 
could not be saved.
Please, try again.', true));
                        }
                }
                $places = $this->Reservation->Place->find('list');
                $means = $this->Reservation->Mean->find('list');
                $this->set(compact('places', 'means'));
        }
......
......
?>

view reservation add.ctp

<?php echo $form->create('Reservation');?>
        <fieldset>
                <legend><?php __('Add Reservation');?></legend>
        <?php
                echo $form->input('place_id');
                echo $form->input('from');
                echo $form->input('to');


                // this show the field "codice", it's ok ... how can I
assign the value cod_mezzi ???
                echo $ajax->autoComplete('codice', '/means/autoComplete');
                
        ?>
        </fieldset>


<?php echo $form->end('Submit');?>
</div>


thanks for the help.

-- 
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
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to