navi83act
(Navi Naveenkumar)
June 12, 2013, 8:52am
1
Hi Pals,
Am new to yii. So, please help me to resolve.
I need to create a dynamic input fields to store and manipulate data from mysql database.
Consider i need to create a configurable column for ‘Departments’ and store using below schema.
CREATE TABLE departments
(
id
int(11) NOT NULL AUTO_INCREMENT,
department_name
varchar(50) NOT NULL,
publish
enum(‘Y’,‘N’) NOT NULL,
created_by
int(11) NOT NULL,
created_date
datetime NOT NULL,
modified_by
int(11) NOT NULL,
modified_date
timestamp NOT NULL DEFAULT ‘0000-00-00 00:00:00’ ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
Please find the attached expected screen shot.
Hope for a solution with sample code
navi83act
(Navi Naveenkumar)
June 12, 2013, 9:05am
3
is it possible to provide full sample code?
Its urgent Pls… help me.
KonApaz:
Hi
You have to create
an action ‘A’ to store new (and unique) department_name, and echoes all departments (with the new department) as array(id1=>‘name1’,id2=>‘name3’) in json format
an input text that will be displayed when you click the new button (by javascript)
an ajax button(save) the calls then above action ‘A’ and refresh combobox items by the returned json of the action A.
konapaz
(Konapaz)
June 12, 2013, 9:46am
4
In your Model
public static function getAllListDepartments() {
$a = self::model()->findAll();
return CHtml::listData($a, 'id', 'department_name');
}
In you controller
public static function addnew($dname) {
$a = new Departments();
$a->departments_name = $dname;
$a->save();
echo CJSON::encode(Departments::getAllListDepartments());
Yii::app()->end();
}
I have no time to post about view code, maybe later