Transition from Controller to View

Audience

Don't take a look at this stuff if you are new to the project. This is for people who care more about the Base MVC architecture. One of the core questions that arises is:

How much and which logic will be in Controller and which in View?

Goals

  • reduce (non-view) logic in views
  • simplify BaseController

BaseViewController: Thoughts about architectural concepts

BaseViewController: Is a special Controller which will be a kind of middleware/sub-layer/helper between the classical Controllers and Views.

Purpose:

This Controller is manly used to reduce the logical hard code php stuff from generic views and to bring the view related stuff from BaseController to a better place - BaseViewController.

This leads to a kind of theoretical sub-layer concept – in fact it is not! See later ..

 

At the time it is not a full qualified sub-layer (API) in this manner that all stuff goes through this Controller,

whats between all Controllers and Views. It's more a kind of "Helper" to increase the logical structuring.

This has the advantage that we do not need a complete re-write.

Usage:

Most of the function here are used in a simple static context from BaseController like BaseViewController::do_prepare_view_xyz().

How much logical in a View ?

See:

https://www.reddit.com/r/laravel/comments/38t0qi/too_much_logic_in_my_view/

If those loops and if statements are related to the visual aspect its not wrong. At least that's what I ask myself somewhere in the back of my head. Are you using for statements to loop through data to display it its OK. If you use an if statement to display an error message its not wrong.

The minute you start using functions to manipulate data or when you feel the need to echo or return something alarm bells should start ringing big time. If you are actually defining functions or setting variables or stuff like that you are definately doing something wrong.

There are exceptions for everything of course but I think these little 'rules' apply 99? of the time. If you want something not as extensive as Angular but want to do some 2 way data bi ding and stuff look into Vue or React. (I'd recommend vue) (get a laracast subscription.

Jeffrey is doing a series on Vue right now)

Architecture Overview