Welcome Guest, Not a member yet? Register   Sign In
How to create a new library and use it with controller?
#1

I am writing a very big application and I think it would be great if i could put that in a library and use it in my controller. How can I easily build up a simple library and use that in my Controller?
Care to give me an example?
Reply
#2

Example:

PHP Code:
<?php

namespace App\Libraries;

/**
 * Class ExampleLibrary
 *
 * @package App\Libraries
 *          
 * in your controller or where you load the library
 *          
 * use App\Libraries\Example;
 */
class ExampleLibrary
{

    
/**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */


    /**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {

    }

    
// -------------------------------------------------------------------

}   // End of ExampleLibrary Library Class.

/**
 * -----------------------------------------------------------------------
 * Filename: ExampleLibrary.php
 * Location: ./app/Libraries/ExampleLibrary.php
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

In your controller, use
Code:
use App\Libraries\ExampleLibrary;
above the class
and then you can instantiate your library class in a method with
Code:
$exampleLibrary = new ExampleLibrary();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB