MVC ... how and why, and what other good options are (PHP)?

All the examples I've seen about how and how MVC SHOULD use classes as models, classes as a controller, and HTML templates as a representation. And all of them consisted of one index.php script and different requests in the URL to launch the entire site.

So they were all kind of ...

MODEL
class User{
    function getUser($userID){
      $sql = mysql_query('SELECT name......');
      // more code.....
      return $array
    }
}

VIEW
<h2><?php echo $user['name']; ?></h2>

CONTROLLER
class Controller{
    $userModel = new User;
    $userInfo = $userModel->getUser($id);

    $template = new Template('usertemplate.tpl');
    $template->setVariables($userInfo);
    $template->display();
}

, , ( , ). , HTML. , . , script (, userprofile.php, ).

, , , , URL-, "index.php? user = 1" index.php? news = 3, . , user_profile.php? Id = 1, news.php? Id = 3...

-, , "" . ... MVC, ? Thankyou

PS.

+3
4

"" PHP- MVC , PHP URL-, .

, URL-, , ( ) / . , "" , , URL/PHP- - URL/PHP-, . , .

, ( , ), , , .

MVC URL-, . , , . URL- - , SEO .

, , , . , MVC, , .

+1

url like "index.php? user = 1", index.php? news = 3 . user_profile.php? id = 1 news.php? ID = 3...

, :

  • - user_profile.php news.php
  • - (, PHPIDS ACL, ), , .

PS.

; ( ) , , , .

+1

, , ​​ MVC, . MVC, .

. , .

, script "register.php"

$signup_options = SignupOptions::getSignupOptions(); // Load some data      
require("register_form.php");  // Pass it to the view

register_process.php

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$email    = $_REQUEST['email'];
Users::Register( $username, $password, $email );
header( 'location: register_success.php' );

MVC , . . MVC -.

"View-Helper", , "", - . , , , , MVC. ( , , ).

0

, . Samstyle PHP Framework.

-, : Model (Table Data Gateway), View, View Controller Backend Controller.

, (, ). Backend ( ).

, Post-Redirect-Get.

, register.php View, HTML .

The user uses the form, submits and then will be sent to the deck.php backend controller. The Backend controller checks, then checks the data for functions (Table Data Gateway) that will help you interact with the database. After the interaction is completed, the user is redirected either to the success page or to the registration page with an error.

In the model (Table Data Gateway) there are actually functions that are accepted in the array, and then CRUD with the database.

0
source

Source: https://habr.com/ru/post/1719854/


All Articles