kbrin80
kbrin80

Reputation: 409

Kohana 3 Controller Constructs

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';
    }

Upvotes: 1

Views: 2092

Answers (3)

Pradeep shyam
Pradeep shyam

Reputation: 1292

You have to use both request and response in construct.

public function __construct(Request $request, Response $response)
{
   parent::__construct($request,$response);
   // your code
}

Upvotes: 5

biakaveron
biakaveron

Reputation: 5483

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.

Upvotes: 3

kbrin80
kbrin80

Reputation: 409

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.

Upvotes: 7

Related Questions