Welcome Guest, Not a member yet? Register   Sign In
Add $this->load->view to all functions?
#3

[eluser]Fredrik-s[/eluser]
[quote author="waldmeister" date="1303655570"]Possible solution would be to write your own function that you call instead of $this->load->view() in your controller. I would extend the CI_Controller class and put that function there:
Create a file called MY_Controller in application/core with this content:
Code:
class MY_Controller extends CI_Controller {
  function __construct() {
    parent::__construct();
  }

  function load_view($view_file, $data) {
    $this->load->view('header');
    $this->load->view($view_file, $data);
    $this->load->view('footer');
  }
}

And now you only have to update your controllers to extend MY_Controller instead of CI_Controller and in your functions you would call $this->load_view('auth/login', $this->data); and remove the $this->load->view('header') and $this->load->view('footer') calls.[/quote]

Thanks for answer!

I run in to a problem though. I have added the code you stated above into my /application/core -folder. Named the file MY_Controller.php.

And in my auth.php file in the folder /application/controllers/ I have changed the following code on the top to extend the MY_Controller class:
Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

if ( ! class_exists('Controller'))
{
    class Controller extends [b]MY_Controller[/b] {}
}

class Auth extends Controller {

From this long I have come I got the following error message stating that it does'nt find the MY_Controller class

Fatal error: Class 'MY_Controller' not found in /home/XXXXX/application/controllers/auth.php on line 8

Of course it can't find it because the file MY_Controller.php is in the core folder and not the controllers. How come this error shows up?


Messages In This Thread
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 02:54 AM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 03:32 AM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 09:48 AM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 09:56 AM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 10:13 AM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 10:21 AM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 01:16 PM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 03:06 PM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 03:30 PM
Add $this->load->view to all functions? - by El Forum - 04-24-2011, 03:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB