Welcome Guest, Not a member yet? Register   Sign In
Setting default variables in a controller
#1

[eluser]deineMudder[/eluser]
Hello i am still a newbie to CI and have a basic question again.

I got my Controller User:

Code:
<?php
class User extends Controller {
function User()
{
  parent::Controller();
  if ($this->session->userdata('logged_in') != TRUE){
   redirect('/admin/login/','location');
  }
}

  function activation()
  {
   $controller = 'user';
   $data['page_vars'] = $this->libadmin->page_vars($controller);
   ...
  }

  function add()
  {
   $controller = 'user';
   $data['page_vars'] = $this->libadmin->page_vars($controller);
   ...
  }

  function search()
  {
   $controller = 'user';
   $data['page_vars'] = $this->libadmin->page_vars($controller);
   ...
  }
....
...
..
.


In order to define some variables im passing the controller to a library to return the variables i want. Now i want to reduce my code a bit and was thinking that i could put the 2 first lines of each function in the controller somewhere into a global variable but it seems im unable to do it Sad

i wanted it to look like this:
Code:
<?php
class User extends Controller {
function User()
{
  parent::Controller();
  
  $controller = 'user';
  $data['page_vars'] = $this->libadmin->page_vars($controller);  

  if ($this->session->userdata('logged_in') != TRUE){
   redirect('/admin/login/','location');
  }  
}

function activation()
  {  
  i wanna be able to access $controller here....
  }


anyone got an idea on how to solve it?


Messages In This Thread
Setting default variables in a controller - by El Forum - 07-15-2007, 12:15 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 02:35 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 02:41 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 02:52 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 02:59 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 03:41 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 03:43 AM
Setting default variables in a controller - by El Forum - 07-15-2007, 04:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB