Welcome Guest, Not a member yet? Register   Sign In
CI Way of Using Own Classes / Code
#1

(This post was last modified: 02-17-2017, 12:34 PM by JustBoo.)

Hello. After searching, reading the CI docs, looking at several online CI project examples and a number of github projects I can't figure this out.

What is the CI best practice to use for our own 'independent' classes and code in relation to CI's structure?

I can only find relevant info from examples in "Creating Libraries" I see 
Code:
$this->load->library('someclass');
From the doc topic "Creating Libraries" I read, "However, since a library is a class, ..."

I'm used to thinking of libraries as external code that comes in some "name.lib" format or, with PHP, like these:
http://tutorialzine.com/2013/02/24-cool-...now-about/

I don't think of my own code as a library. I like bifurcating using  'Separation of Concerns.' Yet, I do not see any example of anyone 'new'ing' classes like in the code snippet below. (Note my question is general, not just about models.)

I've tried the (equivalent example ) code below in a working program; it works. Is it a bad practice to do that?

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

require_once( 'src/BusinessLogic.php' );

class Bigshot_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    
    public function getManagersSalary()
    {
       [...]
        $bi = new BusinessLogic;
        $waste = $bi->calcBloatedEgoCost( $params );
        [...]
    }    
    [...]
?>    
}

I think I understand to get 'native' access to CI functions, et cetera, I may have to make a class a library class. Is it bad practice to pass a reference to $CI into a non-CI derived class?

Thank you.
Reply


Messages In This Thread
CI Way of Using Own Classes / Code - by JustBoo - 02-17-2017, 10:41 AM
RE: CI Way of Using Own Classes / Code - by Shawn - 02-18-2017, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB