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')

November 17 2014

Order by day of the week from Monday to Sunday

Tagged Under :

MySQL
A lot of people may be will ask how to sort day of the week with SQL query. Because Monday to Sunday it was string and MySQL cannot differentiate it was day or string inside the table.

But you are allow define inside the query how order the query with ORDER BY FIELD().

ORDER BY FIELD([fieldname], 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');

ORDER BY FIELD actually is custom ORDER BY in MySQL. It easy to let you sort the results needed by you.

November 14 2014

Getting the number of rows with a GROUP BY query in MySQL

Tagged Under :

MySQL
If you use the COUNT() function with GROUP BY. It will count the number of rows within each group, not the total number of rows. If you want count the number of rows with the groups, you are not allow use GROUP BY inside the query.

Instead of use GROUP BY you may use DISTINCT inside the query. The DISTINCT function similar with GROUP BY, but it can put inside the COUNT() function.

SELECT COUNT( DISTINCT(id) ) FROM table

October 19 2014

Jquery position popup a div near the cursor mouse pointer

Tagged Under :

jquery
Below image was showing you display a div beside the mouse pointer or cursor. when user click the relative text.
div popup
Click Here to check how the code work.

October 16 2014

CSS notification class boxes

Tagged Under :

css3
Web application normally need 4 type of notification. They are ERROR, SUCCESS, WARNING and NOTICE notification. Those type CSS notification class always can reuse in others application as well. You are allow keep the CSS notification class and images inside a folder for next time using it.
css notification
Below is the DEMO CSS Notification class, you can download the css class and images from the url.
DEMO CSS Notification Boxes

September 03 2014

Joomla return site root or main url

Tagged Under :

Joomla
In Joomla the easy way to get complete site domain with the specified folder (if your joomla put in others folder). You can use JURI::root() this function to get it.

How to use this feature:
echo 'Joomla root URI is '.JURI::root()."\n";
echo 'Joomla root URI (path only) is '.JURI::root( true )."\n";
echo 'Joomla root URI (path specified) is '.JURI::root( false, '/a-different-path' )."\n";
echo 'Joomla root URI (path only) (path specified) is '.JURI::root( true, '/a-different-path' )."\n";
echo 'Joomla root URI is '.JURI::root()."\n";
echo 'Joomla root URI (path only) is '.JURI::root( true )."\n";
Output
Joomla root URI is http://localhost/joomla15svn10812/
Joomla root URI (path only) is /joomla15svn10812
Joomla root URI (path specified) is http://localhost/a-different-path/
Joomla root URI (path only) (path specified) is /a-different-path
Joomla root URI is http://localhost/a-different-path/
Joomla root URI (path only) is /a-different-path

August 04 2014

Joomla tinyMCE adding image with full path or full absolute urls

Tagged Under : ,

Joomla
To set tinyMCE editor to full path or full absolute urls, inside tinyMCE.init add the “relative_urls” params to and set the value to “false“. Because this option is set to true by default.
relative_urls : false,
But in Joomla you are not allow directly change the javascript params to false. But you can pass the params in PHP when calling it.

Below is the example how to set the “relative_url” to false. and it work on Joomla2.5
$editor = JFactory::getEditor();
$params = array('relative_urls' => '0');
echo $editor->display('wrapper4_editor', $this->wrapper4content['content'], '100%', '400px', '', '', true,null, null, null, $params);

August 04 2014

Joomla use JPagination in application

Tagged Under :

Joomla
To use JPagination inside the application. You need include the pagination classes inside the application.

You can using jimport to include the Pagination classes.
jimport('joomla.html.pagination');
After that, pass the value to the class.
$total = 100; //the total number of items in a list
$limitstart = 0; //the offset of the item at which to start
$limit = 15; //the number of items to display per page
$pageNav = new JPagination($total, $limitstart, $limit);
After that, echo the pagination output using getListFooter.
echo $pageNav->getListFooter();
Now you can refresh the page and you will able see the pagination output as below: joomla pagination

July 22 2014

Jquery Smooth Scroll to an Element Without Using Plugin

Tagged Under :

jquery
Jquery provide a lot of useful plugin. But sometimes you are allow using pure jQuery to complete the feature.

Below example code showing how to using pure jQuery to completed scroll to element feature.
JQuery smooth scroll example code