Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
redirect problems
  • Hi, Im creating a small admin panel for a website I'm creating.
    To ease the worklayout, I created a subdirectory Admin. In there I caerted a controller admin which extends Controller_template.
    <?php
    
    class Controller_Admin_Admin extends Controller_Template {
     public function before()
     {
      parent::before();
      $this->template->logged_in = false;
      
      if(\Auth::check())
      {
       $user = \Auth::instance()->get_user_id();
       $this->user_id = $user[1];
       $this->template->logged_in = true;
      } else {
       Response::redirect('admin/panel/login');
      }
     }
     
        public function action_404()
     {
      $messages = array('Aw, crap!', 'Bloody Hell!', 'Uh Oh!', 'Nope, not here.', 'Huh?');
      $data['title'] = $messages[array_rand($messages)];
    
      // Set a HTTP 404 output header
      $this->response->status = 404;
      $this->template->content = View::factory('404', $data);
     }
    }
    

    As written in the controller documents, I set the subdirectory in the controllers name. In the routings I wrote the following (within the array brackets):
    'admin'   => 'admin/panel',    // The admin route
    

    For some reason I get a browser error:
    The page isn't redirecting properly
    

    any ideas where the problem might reside?
  • Glad it's sorted :)
    I ran in to a routing issue this morning and thought that something had changed in v1 but it to turned out to be my error so your not on your own :)
  • You can create an admin.php file in app/classes/controller and write :
    class Controller_Admin extends Controller &#123;
    
    ....
    
    public function action_index()
    &#123;
       ...
    }
    
    ...
    
    }
    

    In config/routes.php add :
    'admin'          => 'admin/index',  // Admin Dashboard
    'admin/(:any)' => 'admin/$1',  // Admin Controllers
    
  • Well I don't have any problems with the root controllers. The problem i have is the fact that i have my controller in a sub-directory.
  • May I ask why you have a file in classes/controller/admin/admin.php ? when you could just keep it as classes/controller/admin.php? I think right now it would only be accessible at http://mysite.com/admin/admin/params since it's in a sub directory... If you intend the use this as an controller that all other admin controllers extend then I would leave it in controller/ and extend as Controller_Admin... This way anything in controller/admin/* would be http://mysite.com/admin/*
  • I have my main admin controller setup like that classes/controller/admin/admin.php No routes setup and it works fine It only contains a before() to load \Auth::stuff and action_index() [url=http://fuel/admin]http://fuel/admin[/url] Everyone sets up admin in diferent ways I have a separate admin controller for modules in classes/controller/admin/modules.php Again no route setup [url=http://fuel/admin]http://fuel/admin/modules[/url]
  • @nerdsrescueme: Well the admin/admin.php is a template controller which will be extended by all my admin controllers.
    admin/panel.php would be my main entry page (which extends admin/admin.php). Offcourse, setting the admin controller in th econtroller folder, would make more sense. But as it was routed I thought it would work too. But even thought it is located in the controller I keep getting the redirect problem. @Phil F: I have the same setup, but as I said, for some reason I keep getting a redirect problem.
    So your index in admin/admin.php would be a redirect to your admin panel for example? I thought it would be be the same as routing it.
  • okay I found the mistake.
    as I wrote a redirect to admin/login in the before of the admin controller (when not logged in).
    It kept redirecting in an endless loop.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion