Pages

Friday, May 8, 2015

Understanding Basic Laravel Framework. Model-View-Controller

after installing laravel and get the environment set, we will try to test our code. If you find some issues while installing composer perhaps this link can help you.


Laravel is a framework that use mvc ( model view controller ) architecture.  It means that there are 3 main component that separate function and responsibility between each method.


Controller is used to control the application.  whenever got request from user, what kind of output / response will be served to user. is it a plain html word? or is it retreiving some data from database ( working with model ). or is it showing a template with html css javascript ( working with view ).  Or both ( take some data from model,  put it on view, then serve it to user ).


Controller is the brain of application. It's control the logic of an application we build.


Model is used to talk with database. Using model. we can also give some boundary / limit to what kind of input should be inserted to database. By using model, we make sure there are no harmful code in other area ( from views / controller ) that can change data which doesn't match rules in model.
Laravel also have something called ORM ( object relational mapping ).  We just need to write some code in laravel (php) format to make a database record ( insert, update, query, delete ) without need to write the sql query itself.




View is used to make some template. All presentation ( mostly from front end ) usually live here. Laravel using some kind templating called blade.  the syntax is using {{ //our code here }}. We don't have to type    <?php //xxx ?> . Another way to write some code. Basicly it is still the same but with blade we can write more less code  ( the output to user are still the same).










No comments:

Post a Comment