CodeIgniter Forums
couldn't create own library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: couldn't create own library (/thread-826.html)



couldn't create own library - kavy - 01-20-2015

I created my own library  . how could customized template in library ... iam so new with codeigniter .


RE: couldn't create own library - Avenirer - 01-21-2015

You are new to english too Tongue. What was the question again? (Usually is good to put a question mark if you want something to be answered...)


RE: couldn't create own library - InsiteFX - 01-21-2015

If you access CI in a CI User Library then you need to use the CI Super Object.


RE: couldn't create own library - RobertSF - 01-22-2015

(01-20-2015, 10:25 PM)kavy Wrote: I created my own library  . how could customized template in library  ... iam so new with codeigniter .

kavy, I can't really tell what you're asking, but welcome to CodeIgniter, and don't give up. It will take some time to learn.

Here's a link to a PDF of the documentation for Code Igniter 2.1.2
http://notes.hipopotam.org/file_download/4/CodeIgniter_2.1.2_User_Guide.pdf

If you're just starting with Code Igniter, I advise you not to create libraries yet. Create a few simple applications, like a blog, or product registration, or something like that. When you get more familiar with Code Igniter, you will probably find it easy to add your own libraries.

To avenirer and InsiteFx, come on, folks, don't be mean. Not everyone in the world speaks the Queen's English, and don't throw terms like CI Super Object to a newbie lost on page one. They'll just get loster.  Smile


RE: couldn't create own library - Rufnex - 01-23-2015

To create a library is very simple with CI. First you have to create a File with your Classname in your /application/library folder like

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Rufnex {

    function 
__construct($params)
    {
        
$this->param $params['test'];
        
$this->ci =& get_instance();
    }

    public function 
hello()
    {
        echo 
"hello world";
    }

    public function 
load()
    {
        
$this->ci->load->library('calendar');
        echo 
$this->ci->calendar->generate();
    }

    public function 
param($param)
    {
        echo 
"content of my param: ".$param;
        echo 
"<br />";
        echo 
"content of my class param: ".$this->param;
    }
    


Then you can call your Class in you controller like this

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends MY_Controller {

    function 
__construct()
    {
        
parent::__construct();
    }

    public function 
index()
    {
        
$this->load->library('rufnex', array('test' => 123));
        
$this->rufnex->hello();
        
$this->rufnex->load();
        
$this->rufnex->param('test');
    }


As you see, there is no magic ;o) For further details please refer to the documentaion at http://www.codeigniter.com/user_guide/general/creating_libraries.html