Welcome Guest, Not a member yet? Register   Sign In
Overide Codeigniter ntaive library how ?
#1

[eluser]runrun[/eluser]
So the loader class will always look in views folder to load view. I want to extend the loader library so that it will look in myown_views folder to load view. How can I do that ?
#2

[eluser]InsiteFX[/eluser]
application/core/MY_Loader.php
Code:
class MY_Loader extends CI_Loader {

}

InsiteFX
#3

[eluser]runrun[/eluser]
that's what I've got. I just want to know what to put in the class MY_Loader extends CI_Loader { } ?
#4

[eluser]toopay[/eluser]
Code:
// NOT TESTED, but should works
// Add this within InsiteFX code
function __construct()
{
   parent::construct();
   $this->_ci_view_path = APPPATH.'myown_views/';
}
#5

[eluser]runrun[/eluser]
is that's for CI 2.0 ? I'm using CI 1.7.2 so I guess I should do like this?

Code:
function My_Loader()
    parent::CI_Loader();
    $this->_ci_view_path = APPPATH.'myown_views/';
{
#6

[eluser]runrun[/eluser]
yes I guess right. thanks for helping guys!
#7

[eluser]runrun[/eluser]
I upgraded to CI 2.0.2 today. The code no longer worked. this is my current code.

Code:
class MY_Loader extends CI_Loader {

    function __construct()
    {
       parent::construct();
       $this->_ci_view_path = FCPATH.'myview/';
    }

}

The load class still looks for views folder instead of myview folder.
#8

[eluser]InsiteFX[/eluser]
You are all wrong because it is looking for an associated array!
Also it still may not work because it is being done in the Condtructor!

But you can try this:
Code:
class MY_Loader extends CI_Loader {

    function __construct()
    {
       parent::construct();
       $this->_ci_view_path = array(APPPATH.'myview/' => TRUE);
    }

}
// or
class MY_Loader extends CI_Loader {

    function __construct()
    {
       parent::construct();
       $this->initialize();
    }

    function initialize()
    {
       $this->_ci_view_path = array(APPPATH.'myview/' => TRUE);
    }

}

InsiteFX
#9

[eluser]runrun[/eluser]
I try your suggestion, the core loader library is still looking for the views folder.
#10

[eluser]InsiteFX[/eluser]
Like I said above you can try what I showed you, but in most cases you can not over ride the Constructor!

Maybe like this:
Code:
class MY_Loader extends CI_Loader {

    function __construct()
    {
       parent::construct();
       $this->_ci_view_path = array(
           APPPATH.'views/' => TRUE,
           APPPATH.'myview/' => TRUE
       );
    }

}
Make sure you also leave the view directory in its place!


InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB