{"id":8356,"date":"2020-02-07T10:30:22","date_gmt":"2020-02-07T01:30:22","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8356"},"modified":"2020-02-06T19:03:51","modified_gmt":"2020-02-06T10:03:51","slug":"mvc-architecture","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8356","title":{"rendered":"MVC Architecture"},"content":{"rendered":"\n<p>Today I will talk about what is <em>MVC architecture<\/em> with some PHP sample codes.<\/p>\n\n\n\n<p>MVC means model, view, controller:<\/p>\n\n\n\n<p><strong>Model<\/strong>: refers to the data structure.<br><strong>View:<\/strong> refers to the user interface (UI), with what the user sees and interacts.<br><strong>Controller:<\/strong> is an &#8220;intermediate processor&#8221; located between the model and the view.<br><strong>How it works:<\/strong> the user interacts with the view (UI) to enter some inputs. The controller processes the user&#8217;s request, works with the data model. Finally, the controller will update the view to show the results.<\/p>\n\n\n\n<h3>Model<\/h3>\n\n\n\n<p>It is the representation of information or data that you want to display to user. Model have classes (If you have heard or used Object oriented programming you might have heard about Class). Model gets all these data from database and data can be read, updated and deleted.  <\/p>\n\n\n\n<h3 id=\"d4eb\">View<\/h3>\n\n\n\n<p>It is all the front end code via which the website is presented in front of the user (UI\/UX). It includes all the CSS, HTML and JavaScript. Also Ajax calls are included. Using view, the user interacts with the website.<\/p>\n\n\n\n<h3 id=\"84a4\">Controller<\/h3>\n\n\n\n<p>It contains all the logic of your website. Controller also has class with the all methods and application logic. It does as the interface between the Model and View. Most of the application codes are written in this part.<\/p>\n\n\n\n<p>Check out the PHP sample codes below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n\/\/Model Part\nclass Model \n{\n    public $text;\n    public function __construct() \n    {\n        $this->text = 'Hello world!';\n    }\n}\n\n\/\/View Part\nclass View \n{\n    private $model;\n    public function __construct(Model $model) \n    {\n        $this->model = $model;\n    }\n\n    public function output() \n    {\n        return '&lt;h1>' . $this->model->text .'&lt;\/h1>';\n    }\n}\n\n\/\/Controller Part\nclass Controller \n{\n    private $model;\n    public function __construct(Model $model) \n    {\n        $this->model = $model;\n    }\n}\n\n\n\/\/initiate the model class\n$model = new Model();\n\/\/controller and the view share the model\n$controller = new Controller($model);\n\n$view = new View($model);\n\necho $view->output();<\/code><\/pre>\n\n\n\n<p>These are some popular PHP MVC frameworks.<\/p>\n\n\n\n<ol><li>&#8211; Laravel<\/li><li>&#8211; Symfony<\/li><li>&#8211; Yii 2<\/li><li>&#8211; CakePHP<\/li><li>&#8211; CodeIgniter<\/li><li>&#8211; Zend Framework<\/li><li>&#8211; Phalcon<\/li><li>&#8211; Slim Framework<\/li><li>&#8211; FuelPHP<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>By Yuuma.<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8356\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8356\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"MVC Architecture\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8356\" data-text=\"MVC Architecture\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8356\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8356\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today I will talk about what is MVC architecture with some PHP sample codes. MVC means model, view, controller [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8356"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8356"}],"version-history":[{"count":8,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8356\/revisions"}],"predecessor-version":[{"id":8367,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8356\/revisions\/8367"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}