Welcome Guest, Not a member yet? Register   Sign In
Loading Models in Config Files
#1

[eluser]@MaxG[/eluser]
Hey Guys,

How can I load an model in an config file(ex.: application/config/routes.php)?

Greets
#2

[eluser]Aken[/eluser]
Why? If you're trying to use your database to generate routes, you can't. The database object will not be available when the routes are generated.
#3

[eluser]@MaxG[/eluser]
How can I solve it?

Greetings Wink
#4

[eluser]Narf[/eluser]
You can't. The only thing close to doing that is loading the appropriate model in each controller's constructor:

Code:
class News extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('news_model');
    }

}

... you'll then have it available for use in all methods declared for that controller.
#5

[eluser]@MaxG[/eluser]
Heyo,

I just want to load an Model in the Routes-Config File to load routes dynamically. (Ive installes HMVC).

My Class(application/libraries/route.php):
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Route{
public $_ci;

public function __construct()
{
$this->_ci = get_instance();
}
public function GetAllRoutes()
{
$q = $this->_ci->db->get('routes');
return $q->result_array();
}
public function AddNewRoute($RouteId, $RouteStart, $RouteAim)
{
$ToInsert = array(
'route_id' => $RouteId,
'route_start' => $RouteStart,
'route_aim' => $RouteAim
);
If($this->_ci->db->insert('routes', $ToInsert))
{
return true;
}
return false;
}
}

Greets Smile




Theme © iAndrew 2016 - Forum software by © MyBB