PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] Integrate carbon library in codeigniter 3

 January 01, 2022     codeigniter, php, php-carbon     No comments   

Issue

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 carbon\carbon

Thank you in advance.


Solution

Easy steps:

  1. Direct download: https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Carbon.php

  2. Put Carbon.php at application/libraries

  3. Create Mcarbon.php

    <?php
    
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    require_once dirname(__FILE__) . '/Carbon.php';
    
    use Carbon\Carbon;
    
    class Mcarbon extends Carbon
    {}
    
  4. Put this in your Controller

    $this->load->library ( 'Mcarbon' ); 
    
  5. 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);
    


Answered By - Jetwiz
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing