Hello all !
I just created a new tool to render a form from a database.
There is the repository : https://github.com/Zheness/phalconFormGenerator
It's not perfect, but it's working, and it can save time by generating form.
This is an example of what this tool do (read README file for configuration):
My SQL table:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`firstname` varchar(65) NOT NULL,
`lastname` varchar(65) NOT NULL,
`email` varchar(105) NOT NULL,
`password` varchar(255) NOT NULL,
`isAdmin` tinyint(1) NOT NULL,
`biography` text NOT NULL,
`short_description` varchar(1000) NOT NULL,
`user_status_id` int(11) DEFAULT NULL,
`last_date_login` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_status_id` (`user_status_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
The form generated:
class UsersForm {
private function _Firstname() {
$element = new \Phalcon\Forms\Element\Text("Firstname");
$element->setLabel("Firstname");
$element->addValidator(new \Phalcon\Validation\Validator\StringLength([
"max" => 65
]));
return $element;
}
private function _Lastname() {
$element = new \Phalcon\Forms\Element\Text("Lastname");
$element->setLabel("Lastname");
$element->addValidator(new \Phalcon\Validation\Validator\StringLength([
"max" => 65
]));
return $element;
}
private function _Email() {
$element = new \Phalcon\Forms\Element\Text("Email");
$element->setLabel("Email");
$element->addValidator(new \Phalcon\Validation\Validator\StringLength([
"max" => 105
]));
return $element;
}
private function _Password() {
$element = new \Phalcon\Forms\Element\Password("Password");
$element->setLabel("Password");
return $element;
}
private function _Isadmin() {
$element = new \Phalcon\Forms\Element\Check("Isadmin");
$element->setLabel("Isadmin");
return $element;
}
private function _Biography() {
$element = new \Phalcon\Forms\Element\Textarea("Biography");
$element->setLabel("Biography");
return $element;
}
private function _ShortDescription() {
$element = new \Phalcon\Forms\Element\Textarea("ShortDescription");
$element->setLabel("ShortDescription");
return $element;
}
private function _UserStatusId() {
$element = new \Phalcon\Forms\Element\Select("UserStatusId");
$element->setLabel("UserStatusId");
$element->setOptions([]);
return $element;
}
private function _LastDateLogin() {
$element = new \Phalcon\Forms\Element\Date("LastDateLogin");
$element->setLabel("LastDateLogin");
return $element;
}
public function setFields() {
$this->add($this->_Firstname());
$this->add($this->_Lastname());
$this->add($this->_Email());
$this->add($this->_Password());
$this->add($this->_Isadmin());
$this->add($this->_Biography());
$this->add($this->_ShortDescription());
$this->add($this->_UserStatusId());
$this->add($this->_LastDateLogin());
}
}
The next step is to copy the files in your project, modify labels, add options, add validators/filters, remove fields, etc.
If someone has ideas, feel free to contribute !
I hope this tool will help you !
Merry Christmas to all and to the Phalcon Team !