Extra form element which not in database

I have 3 tables in a db


CREATE TABLE IF NOT EXISTS `tbl_district` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(100) NOT NULL,

  `status` tinyint(3) NOT NULL DEFAULT '1',

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`)

) ENGINE=InnoDB  DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `tbl_city` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `district_id` int(11) NOT NULL,

  `name` varchar(100) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`district_id`,`name`)

) ENGINE=InnoDB  DEFAULT CHARSET=utf8;


ALTER TABLE `tbl_city`

  ADD CONSTRAINT `fk_city_district` FOREIGN KEY (`district_id`) REFERENCES `tbl_district` (`id`) ON UPDATE CASCADE;


CREATE TABLE IF NOT EXISTS `tbl_contact` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `name` varchar(100) NOT NULL,

  `city_id` int(11) NOT NULL,

  PRIMARY KEY (`id`),

  UNIQUE KEY `name` (`name`),

) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;


ALTER TABLE `tbl_family`

  ADD CONSTRAINT `fk_family_city` FOREIGN KEY (`city_id`) REFERENCES `tbl_city` (`id`) ON UPDATE CASCADE

Now I want to use dependent drop down (for district and city) in views/contact/_form.php

Please help me detail…

Note: I use Giix

Thank you

There’s a nice wiki article. :)

Creating a dependent dropdown

Yes I know. But my problem is "district_id" is not in "tbl_contact". I need to add the element in views/contact/_form.php.

Please help me

Ah, OK.

Just add an attribute(property) named "district_id" to your Contact model. CActiveRecord model can have extra properties that have no columns in the table.

Don’t forget to include it in the validation rules.