views:

26

answers:

2

Trying to use __construct inside a controller to assign some variable but it keeps throwing errors. Hoping that someone can lead me in the right direction.

class Controller_Mobile extends Controller {

    public function __construct()
    {
        parent::__construct();      

        $iphoneDetect = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
        $touchDetect = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
        $blackberry = strpos ($_SERVER['HTTP_USER_AGENT'], 'blackberry');
        $android = strpos ($_SERVER['HTTP_USER_AGENT'], 'android');

        $iphoneDetect = true;
        if ($iphoneDetect == true || $touchDetect == true)  
        { 
            $directory = "mobile/iphone";
        }
        else if($android == true)
        {
            $directory = "mobile/android";
        }

    }
    public function action_index()
    {
        $this->request->response = 'I am mobile';
    }
A: 

I actually just found the answer to the question and just thought i would pass it along. In Kohana 3 you use the before() and after() functions.

kbrin80
+1  A: 

If you want to use __construct() method, dont forget about Request variable:

public function __construct(Kohana_Request $request)
{
   parent::__construct($request);
   // your code
}

Thats why you are getting errors with your code.

biakaveron