Answer the question
In order to leave comments, you need to log in
How to customize the application for the database structure?
There are game servers whose resources are stored in the database. I want to make an application that can manage these resources through the web. Everything rests on the fact that all game server administrators have different field names in the database and it becomes necessary to configure the application for the finished database.
That is, it may be that the field with the name is called username , it may be that Name , there are a lot of options, so the user needs to configure them himself through some kind of interface.
Would it be correct to use /config/main.php application settings for these purposes like this?
'params'=>array(
'tbl_profiles'=>array(
'tbl_name'=>'accounts',
'tbl_fields'=>array(
'id'=>array(
'field'=>'id',
'label'=>'ID'
),
'username'=>array(
'field'=>'username',
'label'=>'Ваше имя'
),
'password'=>array(
'field'=>'pass',
'label'=>'Пароль'
),
}
}
}
$model->{Yii::app()->params[tbl_profiles][tbl_fields][username][field]}'
Answer the question
In order to leave comments, you need to log in
This is not very convenient through /config/main.php - because then you will need to provide for the situation so that the whole thing is written to the config when the server administrator wants to modify something “through the interface”.
It's easier to create a couple of tables in the database that will store these fields.
CREATE TABLE IF NOT EXISTS `table_table` (
`table_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
PRIMARY KEY (`table_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
INSERT INTO `table` (`table_id`, `name`) VALUES
(1, 'accounts');
CREATE TABLE IF NOT EXISTS `table_field` (
`table_field_id` int(11) NOT NULL AUTO_INCREMENT,
`table_id` int(11) NOT NULL,
`name` varchar(32) NOT NULL,
`alias` varchar(32) NOT NULL,
`label` varchar(64) NOT NULL,
PRIMARY KEY (`table_field_id`),
KEY `table_id` (`table_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ALTER TABLE `table_field`
ADD CONSTRAINT `table_field_ibfk_1` FOREIGN KEY (`table_id`)
REFERENCES `table_table` (`table_id`) ON DELETE CASCADE ON UPDATE CASCADE;
INSERT INTO `table_field` (`table_field_id`, `table_id`, `name`, `alias`, `label`) VALUES
(1, 1, 'id', 'id', 'ID'),
(2, 1, 'username', 'username', 'Ваше имя'),
(3, 1, 'password', 'pass', 'Пароль');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question