I've rarely used MVC just because me seem like every person uses his own way, I know that MVC came before the web, by reading these links I had a feeling that it seems that understanding one person is not the same as another for the use of MVC:
The second link mentions that Controllers are not mandatory and should only be used in actions
(user actions). If I understand what he said View is the direct responsible for delivering the data to the client (visually speaking) and he communicates with the Model directly as well (without Controller interference), since the Controller communicates with the Model only when there is action of the user and is not responsible for delivering anything (it seems that this point is majority agreement).
Popular frameworks that use MVC (try to use?!?)
Three popular frameworks are CodeIgniter, Laravel, and CakePHP. All work the Routes using the Controller, example with Laravel:
routes.php:
<?php
Route::resource('', 'DemoController');
DemoController.php:
<?php
class DemoController extends BaseController
{
public function index()
{
//Chama o views/Demo/index.blade.php
return View::make('Demo.index', compact('data'));
}
...
DemoModel:
index.blade.php:
<!DOCTYPE HTML>
<html>
<body>
<div id='content'>
Output: {{ $data }}!
</div>
</body>
</html>
The cakePHP equivalent:
use Cake\Routing\Router;
Router::connect('/', ['controller' => 'DemoController', 'action' => 'index']);
and creates the file ctp
The codeigneter equivalent:
routes.php:
$route['default_controller'] = 'DemoController';
controller:
class DemoController extends Controller {
private $data;
public function __construct(){
parent::Controller();
}
public function index()
{
$this->data['helloworld'] = 'Hello World';
$this->load->view('Demo', $this->data);
}
}
A doubt
I understood, even though the Model data does not pass through the Controller yet the Controller is responsible for calling Model and View (at least in the frameworks cited) , or the Controller calls the View and it calls the Model, anyway the controller is the trigger (if I understand correctly).
In other words, whether or not in the Web, the Controller will always need to do so, not only because of routes, but also because of the simple reason that anything on a web page has the meaning CRUD (Create, Read, Update, Delete), when opening the homepage of a site we are doing a READ, right?
So my question is: Are frameworks using Controllers wrong, or is any HTTP request considered a action
and this would technically be user action (which would force the routes to be Controllers)?
Or does anyone really use MVC strictly?