Welcome Guest, Not a member yet? Register   Sign In
Accessing controller methods from within library class
#1

[eluser]Unknown[/eluser]
I have a library 'system/application/library/Uac.php':

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

class Uac {

    function create_account($user) {
        $password = 1;
        $this->_salt_password($password);
    }  

    private function _salt_password($password) {
        echo $this->config->item['encryption_key'];
    }  
}

I would like the method _salt_password to be able to access the $this->config object from the calling class, however I'm not too sure about what the best way to do this would be. It seems like I should be able to access this sort of stuff from within my library without having to pass them in as arguments but I'm not too sure how I'd go about doing it. If anyone could give me some guidance it would be much appreciated, I'm still trying to get my head around this whole OOP and MVC thing.

My apologies if this has been answered before - I did try searching but was unable to find anything.

The calling class is 'system/application/controllers/test.php':

Code:
<?php
class Test extends Controller {

    function index() {
        $this->load->library('uac');
        $user = 'fs';
        $this->uac->create_account($user);
    }  
}
#2

[eluser]Madmartigan1[/eluser]
Do you need the entire config object specifically from the caller, or just a certain config item, or just need access to the entire global config?

Or something else and I missed the point?
#3

[eluser]Boris Strahija[/eluser]
If I understand correctly you just need an value from a config file in your library? Then you're just missing this in your constructor:
Code:
$this->ci =& get_instance();

And then in your library methods you can access all CI stuff like this:
Code:
$enc_key = $this->ci->config->item('encryption_key');

I hope this helps




Theme © iAndrew 2016 - Forum software by © MyBB