i’m having hard time trying to integrate the grate DateTime Library carbon library with in my project in codeigniter 3 I tried this
$this->load->library('carbon');
and it’s give me an error
not existing class
i think the problem is namespaces because carbon uses namespace carboncarbon
Thank you in advance.
Advertisement
Answer
Easy steps:
Direct download: https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Carbon.php
Put Carbon.php at application/libraries
Create Mcarbon.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once dirname(__FILE__) . '/Carbon.php'; use CarbonCarbon; class Mcarbon extends Carbon {}
Put this in your Controller
$this->load->library ( 'Mcarbon' );
Call Carbon method in any function. Example:
<?php $dt =Mcarbon::createFromDate(2018,2,13,null); var_dump($dt->year); var_dump($dt->month); var_dump($dt->day); var_dump($dt->hour);