I am working on a MVC site, but I have a problem. I can not return anything from my controllers. I can do things like $this->someMethod()
but not return "hello"
I think it has to do with call_user_func_array()
So how do I fix this?
My code:
Router:
Class App
{
protected $controller = 'home';
protected $method = 'index';
protected $parameters = [];
public function __construct()
{
$url = $this->Url();
if(file_exists('../app/controllers/'. $url[0] .'.php')){
$this->controller = $url[0];
unset($url[0]);
}
require_once '../app/controllers/'. $this->controller .'.php';
$this->controller = new $this->controller;
if (isset($url[1])){
if (method_exists($this->controller, $url[1])){
$this->method = $url[1];
unset($url[1]);
}
}
$this->parameters = $url ? array_values($url) : [''];
call_user_func_array([$this->controller, $this->method], $this->parameters);
}
public function Url()
{
if(isset($_GET['url'])){
$url = filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL);
$exploded_url = explode('/', $url);
return $exploded_url;
}
}
}
Public Index.php:
<?php
require_once '../app/core/init.php';
$app = new App;
A controller:
class Home extends Controller
{
public function index($name)
{
//this works.
$this->view('index');
//this does not work.
return "hello";
}
}
So how do I solve it, so the return
works too?
my own framework
! – Hackerman 3 hours ago