header command in PHP

0

I'm trying to create a simple MVC system in which I have the following folder structure:

Arquivos de Código-Fonte - Pasta
  Servlet - Pasta
     UserServlet.class.php
  Controller - Pasta
     UserController.class.php
  Model - Pasta
     DAO - Pasta
        UserDAO.class.php
     VO - Pasta
        UserVO.class.php
  View - Pasta
    userForm.php
  index.php

I need to make my index.php call the class Servlet , for this I put the following code:

<?php
    header('Location : Servlet/UserServlet.class.php?action=goHome');
?>

But the problem is that nothing happens and I need to call the Servlet class so that I can handle which method I'm going to use. If anyone knows a solution, a way for me to be able to make an HTTP request on Servlet will help me a lot.

    
asked by anonymous 14.07.2017 / 00:11

1 answer

0

You will not be able to do this with header ('Location:'), because when working with classes you need to instantiate an object and call a method.

You can do this:

require 'Servlet/UserServlet.class.php';

$class = 'UserServlet';
$method = 'goHome';

$class = new $class;
call_user_func(array($class, $method));

A few years ago I created a project similar to your idea, I called Jiraya Framework, and I used it to work with small projects using MVC and friendly urls, take a look link

    
14.07.2017 / 21:03