PHP using MVC

Asked

Viewed 213 times

0

I’m creating an application in PHP (without frameworks) using MVC, but I’m having a lot of doubts, because until today I only used Symfony to make PHP applications. I have doubts about the routing of urls and use of functions. Here is an example of how my project is currently:

Structure:

api-system

  • pub

    • index php.
  • src

    • Controller
      • Usercontroller.php
    • Model
      • User.php
  • Templates

    • index.html.Twig

File Usercontroller.php

class UserController{
    public function insertUser(){
        //execução

        return json_encode($resultado);
    }

    public function delteUser(){
        // execução

        return json_encode($resultado);
    }

}

User.php file

class User {

    public $id;
    public $name;

function getId(){
     return $this->id;
}

My questions are: How do I routing to access "api.example/insertUser" (I will have another client application that will consume this api)

(I’m using Apache’s Virtualhost, directed to /var/www/system-api/pub )

  • I think you should find out about PSR-4 autoloader: http://www.php-fig.org/psr/psr-4/ ( There are also other standards )

  • 1

    Related: http://answall.com/questions/69178/mvc-duvida-sobre-controller-e-view-php

  • Thanks for the links!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.