Welcome Guest, Not a member yet? Register   Sign In
using libraries in models
#10

[eluser]David B.[/eluser]
Hello,

I think I have kind of a similar problem. I'm not autoloading the model but I'm loading the the library in the constructor of my model. And I can not access the methods of the library in the constructor - only afterwards.

Please, can someone describe what is the problem with this?
And would the preferred solution for that be an additional init-method in the model that then should be called in the controller after loading the model?

E.g.:

Controller:
Code:
class Mycontroller extends Controller
{
    function someFunction()
    {
        $this->load->model("mymodel");
        $this->mymodel->init();
    }
}

Model:
Code:
class Mymodel extends Model
{
    function __construct()
    {
        parent::Model();
        $this->load->library("MyLib");
        
        // doesn't seem to work...
        //$this->mylib->setSomething("some value");
    }

    public function init()
    {
        $this->mylib->setSomething("some value");
    }
}

Thanks for your thoughts!

David


Messages In This Thread
using libraries in models - by El Forum - 05-29-2008, 01:47 PM
using libraries in models - by El Forum - 05-29-2008, 01:52 PM
using libraries in models - by El Forum - 05-29-2008, 02:16 PM
using libraries in models - by El Forum - 05-29-2008, 07:02 PM
using libraries in models - by El Forum - 05-29-2008, 07:54 PM
using libraries in models - by El Forum - 05-29-2008, 08:08 PM
using libraries in models - by El Forum - 05-29-2008, 08:14 PM
using libraries in models - by El Forum - 05-30-2008, 11:18 AM
using libraries in models - by El Forum - 05-30-2008, 11:34 AM
using libraries in models - by El Forum - 06-02-2008, 07:42 AM
using libraries in models - by El Forum - 06-02-2008, 03:30 PM
using libraries in models - by El Forum - 06-02-2008, 10:35 PM
using libraries in models - by El Forum - 06-03-2008, 01:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB