Store content / variables in Model - PHP MVC

4

Hello,

I'm starting to study the MVC standard for PHP. I have read several questions here in StackOverflow, I have already studied the Laravel documentation and read several articles.

I chose the concept covered in this post as a basis - link

From this came a first doubt:

I'm creating a simple site, initially without a database. I have only a few variables for each page ($ title, $ tags, $ description, etc), an array with values, and the foreach. Should I store all these variables in the Model of my pages? (Eg HomeModel, AboutModel, etc.) and move directly to the view?

The diagram below confers?

I ask this question, because I have seen in several tutorials the variables being stored in the Controller, as well as the Views being triggered in the Controller. And the Model being used basically for access and request queries to the Database.

Thank you!

UPDATE:

Beauty, I think I get it. I'm going to take a look at the question you asked too. Thanks!

Just to illustrate how I'm doing at the moment:

I have in my route:

$route->get( '/', 'HomeController@index' );

In HomeController I have this:

class HomeController {

        public function index() {

            $model = new HomeModel;
            return view( 'home', $model );

        }

}

And finally in HomeModel I have:

class HomeModel {

    public $title;
    public $description;

    public function __construct() {

        $this->title = 'Título do meu site';
        $this->description = 'Descrição do meu site';

    }

}
    
asked by anonymous 12.09.2016 / 03:32

1 answer

-1

I recommend that you use these variables in the controllers because the use of templates is only necessary when using the database, ideally this information should be in the database, but not yet, definitely in the controller. A view can not access the model, there is always the bridge that is the controller.

    
12.09.2016 / 04:14