I use PHP5 to create my own MVC framework. I have a situation where all my controllers are in the Controller namespace, for example:
namespace Controllers
{
class Home extends \Framework\Core\Controller
{
...
}
}
In the application logic, I need to select the controller for the call from the URL passed from the call, as follows:
namespace Framework\Core;
class Application
{
protected $controllerName = 'home';
protected $methodName = 'index';
protected $controller;
public function __construct()
{
$url = parseUrl();
if (file_exists('../app/controllers/' . $url[0] . '.php'))
{
$this->controllerName = $url[0];
unset($url[0]);
}
require_once '../app/controllers/' . $this->controllerName . '.php';
$objToCall = '\\Controllers\\' . $this->controllerName;
$this->controller = new $objToCall(); <<<======= PROBLEM HERE
... Proceed choosing the method and calling the objects method....
}
}
}
My problem:
My controller file is called home.php, and my class is called Home(first letter in uppercase). Therefore, the above code cannot find the class /Controllers/home, because the class/Controllers/home
On the other hand, if I remove the namespace from the controller and call:
$this->controller = new $this->controllerName;
It works great, even the name Home....
My questions:
a) Why is the house transferred to Home if I don't have namespaces?
b) ?
, , , CustomerReceipt, PersonalCashWithdrawl ..
.