Ejemplo n.º 1
0
 public function before()
 {
     parent::before();
     $param = $this->request->param('forum');
     $forum = Model_Forum::factory($param)->load();
     try {
         if (!$forum->loaded()) {
             throw new Kohana_Exception('Forumet :forum existerar inte.', array(':forum' => $param));
         }
         $roles = $forum->roles->as_array(NULL, 'name');
         if (!$this->auth->has_roles($roles)) {
             throw new Kohana_Exception('Du måste vara inloggad för att ha tillgång till forum/:forum.', array(':forum' => $forum->name));
         }
     } catch (Kohana_Exception $e) {
         $this->message_add($e->getMessage(), 'error');
         $this->request->redirect('forum');
     }
     // Save forum for later use
     $this->_forum = $forum;
     // REST-thingy
     switch (Request::$method) {
         case 'POST':
             $this->request->action = 'create';
             break;
         case 'DELETE':
             $this->request->action = 'delete';
             break;
     }
 }