December 21 2014

Yii2 sql user table schema

Tagged Under :

Yii
In Yii2 they didn’t provide proper SQL user table schema for the developer.
Below was the Yii2 user table schema, and it can be run on MySQL Database.
CREATE TABLE IF NOT EXISTS `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) NOT NULL,
  `auth_key` varchar(32) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `password_reset_token` varchar(255) NOT NULL,
  `email` varchar(100) NOT NULL,
  `status` smallint(10) NOT NULL,
  `role` int(11) NOT NULL,
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
);
And the data.
INSERT INTO `user` (`id`, `username`, `auth_key`, `password_hash`, `password_reset_token`, `email`, `status`, `role`, `created_at`, `updated_at`) VALUES
(1, 'admin', '', '$2y$13$uqe3LPW9ya3RZhynJpPN5um9fvdxUmoqjOqQBJDdIDXSKxRZB5bPu', '', '', 10, 0, 0, 0);
Now you can login with username admin and password 123qwe

December 11 2014

Yii model rules dynamic required if extension

Tagged Under :

Yii
This extension is use to validate the field is required or not required depends by another field.

For Example, now the form have 2 fields, they are Name and Email. You can set if Name was not empty then Email field will become required to force the user enter the value.

In the Model rules you just include the extension file and then set the if value for which object only.
array('email', 'ext.requiredif', 'if' => 'name')