Hello to all, I have been trying to write a dynamic district and city
select in cakephp 1.2 using Ajax Helper.
These are the code I wrote, but it isn't work.
I have two db tables, cities and districts in which I have insert all
the Italian district and cities.
Then I have a controller, course_controller.php in which I have
function add() {
if(!empty($this->data)) {
if($this->Course->save($this->data))
{
$this->Session->setFlash(__('Course saved',true));
$this->redirect(array('action' => 'index'));
}
else
{
$this->Session->setFlash('Error');
}
}
$this->set('districts',$this->Course->City->District->find('list'));
in order to save the Data Form.
In cities_controller.php I put
function getCities() {
$district_id = $this->data['City']['district_id'];
debug($district_id);
$cities = $this->City->find('list',array
('conditions' => array('City.district_id'=>$district_id)));
$this->set('cities',$cities);
}
And in views/cities/getCities.ctp I have
<?php
echo "<option value=\"0\"></option>";
foreach($cities as $k=>$v) : ?>{
<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
<?php endforeach; ?>
After all in views/courses/add.ctp I have
<?php
echo $form->create('Course');
echo $form->input('district_id',array('empty'=>true));
echo $form->input('city_id',array('type'=>'select'));
echo $form->end('Crea Corso');
echo $ajax->observeField('CourseDistrictId',
array(
'url' => array('controller'=>'cities','action'=> 'getcities'),
'update' => 'CourseCityId',
'frequency' => 0.2,
)
);
$this->render('/cities/getCities');
?>
Ofcourse in my app_controller I have
var $helpers = array('Html', 'Form', 'Ajax', 'Javascript',
'Session', 'Number');
and in my default.ctp I have
echo $javascript->link('prototype',false);
echo $javascript->link('scriptaculous',false);
After all, this isn't work at all, and when I select a district the
city select will not update at all.
Can somebody help me ?
thank you for all.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en