Controller class of mvc

Hello,

Im building a site in mvc. Now i have written this controller class. But i cant capture the get variable inside the class using another variable $action1. But if I use switch($_GET[‘cat’]){} it works. Why isn’t it working this way???
this is the error im getting;

Parse error: syntax error, unexpected T_VARIABLE

And this is the code.

class BaseController{

static $action1 = $_GET[‘cat’];

public static function get_cat(){

switch($action1){

case “gui”:
$rec=Category::display_sub_cat(1);
include(VIEW_PATH.‘category.php’);
return $rec;

case “wwind”:
$rec=Category::display_sub_cat(2);
include(VIEW_PATH.‘category.php’);
return $rec;

}}}

Also after using switch($_GET[‘cat’]){} the page ‘category.php’ is not getting included. No errors but the file is not getting included… Please someone help me to solve this.

You should add some init method, to initialize those static properties with dynamic values:


<?php
...
static public function init( $action )
{
    self::$action = $action
}
...

BaseController::init($_GET['cat']);
?>

Yes definitely.

REF:
http://php.net/manual/en/language.variables.scope.php

Read the paragraph:Example #7 Declaring static variables

You can’t assign a variable to a static variable, only a constant value.


static $a = 1; // works
static $b = 'hello'; // works
static $c = $_GET['bla']; // doesn't work
static $d = $a; // doesn't work