Monday, 7 January 2019

Date Format Compatiblity Cross Browser

Solution 1
Using a format date from momment js (plugin)
moment().format('MMMM Do YYYY, h:mm:ss a'); // January 7th 2019, 2:48:53 pm
moment().format('dddd');                    // Monday
moment().format("MMM Do YY");               // Jan 7th 19
moment().format('YYYY [escaped] YYYY');     // 2019 escaped 2019
moment().format();                          // 2019-01-07T14:48:53+08:00
The Solution
The problem lies in the format that you pass the required date to the Date() object. For some reason, and don’t ask me why, the two aforementioned browsers surprisingly do not support the date format “yyyy-mm-dd” and therefore fail. I haven’t managed to compile a definitive list of supported date formats, however I can tell you the following formats are definitely supported across all browsers and would advise sticking to one of these to avoid errors:


  1. var d = new Date(2011, 01, 07); // yyyy, mm-1, dd  
  2. var d = new Date(2011, 01, 07, 11, 05, 00); // yyyy, mm-1, dd, hh, mm, ss  
  3. var d = new Date("02/07/2011"); // "mm/dd/yyyy"  
  4. var d = new Date("02/07/2011 11:05:00"); // "mm/dd/yyyy hh:mm:ss"  
  5. var d = new Date(1297076700000); // milliseconds  
  6. var d = new Date("Mon Feb 07 2011 11:05:00 GMT"); // ""Day Mon dd yyyy hh:mm:ss GMT/UTC  
Reference
http://biostall.com/javascript-new-date-returning-nan-in-ie-or-invalid-date-in-safari/
https://momentjs.com/

Tuesday, 18 December 2018

jQuery Validation

var validator = $("#signupform").validate({
    rules: {
        firstname: "required",
        lastname: "required",
        username: {
            required: true,
            minlength: 2,
            remote: "users.php"
        }
    },
    messages: {
        firstname: "Enter your firstname",
        lastname: "Enter your lastname",
        username: {
            required: "Enter a username",
            minlength: jQuery.format("Enter at least {0} characters"),
            remote: jQuery.format("{0} is already in use")
        }
    }
}
Example of custom message error

https://stackoverflow.com/questions/2457032/jquery-validation-change-default-error-message/2457053

Thursday, 18 October 2018

Problems Encountered During Cloning

Reference

Laravel server 500
https://stackoverflow.com/questions/28893710/whoops-looks-like-something-went-wrong-laravel-5-0

Laragon Virtual Host Restart
https://sourceforge.net/p/laragon/tickets/14/

Sunday, 5 August 2018

Codeigniter - fetch_class( ) and fetch_method ( )

Hi,
It looks like the following is working in CI 2.1.0
To get the name of the controller in CodeIgniter:
$this->router->fetch_class();
To get the name of the method in CodeIgniter:
$this->router->fetch_method();
Are these methods consider private? Should they be documented if they are public?
thanks.

Thursday, 2 August 2018

site_url and base_url

Oftently or occasionally way of using site_url and base_url variable

1. site_url

when including inside of "application" folder dealing with accessing view and controllers in codeigniter

2. base_url

when to include assets like js, css and images file from root project folder

Visual Code (Goto Definition) using Php IntelliSense

files > preferences > settings

In user settings :



{
    "php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.2.4\\php.exe",
    "php.executablePath": "C:\\wamp64\\bin\\php\\php7.2.4\\php.exe"
}

Friday, 13 July 2018

array_push() merging multiple array

That's because you're adding a non-object to the last element of the array.
Here i suppose you get an array of objects with the name property
$competition_all = Competition::all();
Here you add a key=>value pair to the last element of the objects array
$newCompete = array('name'=>'Others');
array_push($competition_all, $newCompete);
Here you walk through the array of objects and when it comes to the last element the "$competition_games->name" has no name property
foreach ($competition_all as $competition_games) {
            $this->competition_games[$competition_games->name] = $competition_games->name;
        }
Try something like including a stdclass for it like :
$newCompete = new StdClass();
$newCompete->name = 'Others';
array_push($competition_all, $newCompete);