Mini Framework Mvc

0

This is the error you are having when I call this method on my controller

  

Warning: end () expects parameter 1 to be array, null given in   C: \ xampp \ htdocs \ php_mvc \ Libs \ System.php on line 55

     

Warning: array_pop () expects parameter 1 to be array, null given in   C: \ xampp \ htdocs \ php_mvc \ Libs \ System.php on line 56

My class that does the Urls configuration

class System
{
    private $Url;

    private $Explode;

    public $Controller;

    public $Action;

    public $Params;

    function __construct()
    {
        $this->setUrl();
        $this->setExplode();
        $this->setController();
        $this->setAction();
        $this->setParams();
    }


    //Recebe as Urls
    private function setUrl(){
        $_GET['url'] = $_GET['url'] ? $_GET['url']."/" : "Index/Index";
        $this->Url = $_GET['url'];
    }

    //Transforma a url em Arrays
    private function setExplode(){
        $this->Explode = explode("/", $this->Url);
    }

    //Seleciona o Controller
    private function setController(){
        $this->Controller = $this->Explode[0];
    }


    //Seleciona a Action
    private function setAction(){
        $action = ($this->Explode[1] || $this->Explode[1] == null || $this->Explode[1] == "Index"  ? "Index": $this->Explode[1]);
        $this->Action = $action;
    }

    public function setParams() {
        unset($this->Explode[0]);
        unset($this->_explode[1]);

         if (end($this->Explode) == null )
             array_pop($this->Explode);

         $i = 0;
         if (!empty($this->Explode)) {
             foreach ($this->Explode as $val) {
                if($i % 2 == 0) {  // %= indice de 2
                    $ind[] = $val;
                } else {
                    $value[] = $val;
                }
                $i++;
             }
         } else {
             $ind = array();
             $value = array();
         }

         if(count($ind) == count($value) && !empty($ind) && !empty($value))
             $this->Params = array_combine ($ind, $value);
         else
             $this->Params = array();
         }




    public function getParams($name = null) {
        if($name != null){
            return $this->Params[$name];
        }else{
            return $this->Params;
        }
    }

    //Inicia as Urls
    public function run(){
        $controller_path = CONTROLLERS.$this->Controller.".php";

        if (!file_exists($controller_path)) {
            die("Houve um erro o $controller não existe");
        }else{
            require($controller_path);
            $controller = new $this->Controller();

        }

        if (!method_exists($controller, $this->Action)) {
            die("Houve um erro a {$this->Action} não existe");
        }else{
            $action = $this->Action;
            $controller->$action();
        }
    }
}

And My Controller

class Controller extends System{

    function __construct()
    {

    }

    /*Função que ira verificar o nome da View e retornará ela ao
    seu Controller*/
    protected function View($View)  {

        return require('View/'.$View.'.php');
        exit();
    }
}

My Index Controller

class Index extends Controller
{   
    function __construct()
    {

    }

    public function Index(){

        echo $this->getParams("nome");
    }
}
    
asked by anonymous 07.02.2017 / 13:22

0 answers