Welcome Guest, Not a member yet? Register   Sign In
Problems creating and using libraries
#1

[eluser]Unknown[/eluser]
Hi everyone!

I'm developing an application, and have some problems using the libraries i'm creating.
Details below:

.:::. Inside /application/libraries/ folder i have to files:

Soap.php
Code:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Soap extends CI_Controller {
    public function __construct() {
        parent::__construct();
    }

    public function getAlgo() {
        return "algo";
    }

}


Demo.php
Code:
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Demo extends CI_Controller {
    public function __construct() {
        parent::__construct();
    }

    public function getDemo() {
        return "Demo";
    }

}

.:::. Inside /application/controllers/ folder i have a controller:

sce.php
Code:
<php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    class Sce extends CI_Controller {

        public function __construct() {
            parent::__construct();
            $this->load->helper('url');
            $this->load->library('session');
            $this->load->library('encrypt');
            $this->load->library('soap');
            $this->load->library('demo');
        }

        public function showSCE() {
            echo $this->soap->getAlgo();
            echo $this->demo->getDemo();
        }

    }

    ?&gt;;


:::. Executing: http://localhost/app_demo/index.php/sce/showSCE

Quote:A PHP Error was encountered

Severity: Notice
Message: Undefined property: Sce::$demo
Filename: controllers/sce.php

Fatal error: Call to a member function getDemo() on a non-object in
C:\xampp\htdocs\app_demo\application\controllers\sce.php on line xx



.:::. This error shows up when I use the two libraries, but if i only use one works !!!!!. Someone who can help me?
#2

[eluser]CroNiX[/eluser]
Libraries are standalone classes - they don't extend CI_Controller.

If you need to use CI objects within your library, you need to bring in the CI instance into the library.
https://ellislab.com/codeigniter/user-gu...aries.html
#3

[eluser]Unknown[/eluser]
Ty so much!!!!




Theme © iAndrew 2016 - Forum software by © MyBB