{"id":544,"date":"2015-01-26T07:28:47","date_gmt":"2015-01-26T07:28:47","guid":{"rendered":"http:\/\/www.cakephpexpert.com\/blog\/?p=544"},"modified":"2015-01-26T09:57:47","modified_gmt":"2015-01-26T09:57:47","slug":"build-your-first-website-with-cakephp-in-three-easy-steps","status":"publish","type":"post","link":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps","title":{"rendered":"Build Your First Website with CakePHP in Three Easy Steps"},"content":{"rendered":"<p>For people who are new to CakePHP, Cake is a <a title=\"7 PHP Frameworks To Help You Build Rapid Applications\" href=\"http:\/\/www.cakephpexpert.com\/blog\/7-php-frameworks-to-help-you-build-rapid-applications\">PHP framework<\/a>, which closely follows the Model-View-Controller format and standards. <!--more-->As a result of this, the application layers can be separated quite well. The only thing is that with this application, more files and folders are added but the end results are satisfactory. Among different kinds of web applications, the MVC pattern is gaining popularity. Along with this concept, Cake also follows the Convention-Over-Configuration methodology. With this, the amount of code that needs to be written gets reduced considerably.<\/p>\n<p><a href=\"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-545\" src=\"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg\" alt=\"Cakephp development\" width=\"740\" height=\"350\" srcset=\"https:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg 740w, https:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350-300x141.jpg 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/a><\/p>\n<p><strong>Creating a model with CakePHP<\/strong><\/p>\n<p>At the very first place, Cake is installed on the local server and a database is setup followed by creation of Products table. The next step is creating a model, which will be able to correspond to the created table in the database. With Cake, the model names should always be singular, while the table names should be in plural. With this convention, you can create <em>Product.php<\/em> within the directory <em>cake_root\/app\/models folder<\/em>.<\/p>\n<p>Once a blank new PHP file is there, you can start coding. The simplest model form in Cake is PHP class declaration. The CakeAppModel class is the parent of all models. Though not mandatory, each class has a variable \u2013 a name as it makes defining the thing easier.<br \/>\nThe main function of a model is to grab all the available data. The model is nothing but a PHP class and the singular version of the table name. After the collection of the whole data, it is transferred to the suitable controller. The next step is the creation of the Controller.<\/p>\n<p><strong>Controller Creation<\/strong><\/p>\n<p>For naming Cake Controllers, just adding \u2018Controller\u2019 to the table name will do. However, for file names, adding an underscore in between will be good enough. Therefore, the name of the controller file will be <em>products_controller.php<\/em>. The directory which will contain all the controllers is <em>cake_root\/app\/controllers<\/em>. You can create the file within the directory now and once that is done, coding the controller can begin.<\/p>\n<p>For the working of the controller, a class has to be defined specifically, which is the child of the AppController class. Along with this, there are many other things about a controller. The main function of the controller is to access data from the model, process it and then route the same for display in \u2018View\u2019. With more data, the applications get more complex and so do the controllers. Therefore, we intend to work with the index ( ) function. This function is like any root view as in any normal web page. What we need to do is grab the data, put it inside the function and then pass it to view. The data passing is done by using basic Cake controller called set ( ). This function sets a variable to the data provided and passed to view.<\/p>\n<p>The file name comes with an underscore but the name and the class name do not have the same. There is also the name variable as a precaution. Then the first function has to be defined, which is defining index ( ) function in this case. All data are collected from the products table and then a Data variable is set to pass it to view.<\/p>\n<p>The page routing for Cake operates from the URL of the page. <em>Mod_write<\/em> is used for proper display of the page content. Any CakePHP application uses the decoding for page content display <em>http:www.somesite.com\/cake_root\/controller\/method\/method<\/em> argument.<\/p>\n<p><strong>Creating View<\/strong><\/p>\n<p>At first, a view file needs to be created. In the Cake directory, there is a <em>\/app\/views folder<\/em>. Inside the folder, each controller has its own folder. Views are there in each controller folder, the names of which are based on the methods in the controller. So, the file will be <em>cake_root\/app\/views\/products\/index.php<\/em>. Once the file is created, it can be opened. The views are not complete HTML files. They are covered inside a layout. There are many elements that can be there in the layout.<\/p>\n<p>With this view, the MVC hierarchy gets completed. The first Cake page is ready to be up and running. Browsing <em>http:\/\/localhost\/cake_root\/products<\/em> will give the product data along with a query table (Cake generated).<\/p>\n<p>This is how the simplest page can be created with Cake PHP. If you are looking for custom cakephp web application development services, hire us at <a title=\"Cakephpexpert.com\" href=\"http:\/\/www.cakephpexpert.com\/\">Cakephpexpert.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For people who are new to CakePHP, Cake is a PHP framework, which closely follows the Model-View-Controller format and standards.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,12],"tags":[115,31,63],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v16.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Build Your First Website with CakePHP in Three Easy Steps - Cakephp Expert Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Build Your First Website with CakePHP in Three Easy Steps - Cakephp Expert Blog\" \/>\n<meta property=\"og:description\" content=\"For people who are new to CakePHP, Cake is a PHP framework, which closely follows the Model-View-Controller format and standards.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps\" \/>\n<meta property=\"og:site_name\" content=\"Cakephp Expert Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-01-26T07:28:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-01-26T09:57:47+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/#website\",\"url\":\"https:\/\/www.cakephpexpert.com\/blog\/\",\"name\":\"Cakephp Expert Blog\",\"description\":\"Cakephp Development Company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.cakephpexpert.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg\",\"contentUrl\":\"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#webpage\",\"url\":\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps\",\"name\":\"Build Your First Website with CakePHP in Three Easy Steps - Cakephp Expert Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#primaryimage\"},\"datePublished\":\"2015-01-26T07:28:47+00:00\",\"dateModified\":\"2015-01-26T09:57:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/#\/schema\/person\/0f12b00f339dcf099f8431b3ba0db2e1\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.cakephpexpert.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Build Your First Website with CakePHP in Three Easy Steps\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/#\/schema\/person\/0f12b00f339dcf099f8431b3ba0db2e1\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.cakephpexpert.com\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/28e9fe1b5e695a0ed4f8d10cb1186b26?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/28e9fe1b5e695a0ed4f8d10cb1186b26?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\/\/www.cakephpexpert.com\/\"],\"url\":\"https:\/\/www.cakephpexpert.com\/blog\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Build Your First Website with CakePHP in Three Easy Steps - Cakephp Expert Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps","og_locale":"en_US","og_type":"article","og_title":"Build Your First Website with CakePHP in Three Easy Steps - Cakephp Expert Blog","og_description":"For people who are new to CakePHP, Cake is a PHP framework, which closely follows the Model-View-Controller format and standards.","og_url":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps","og_site_name":"Cakephp Expert Blog","article_published_time":"2015-01-26T07:28:47+00:00","article_modified_time":"2015-01-26T09:57:47+00:00","og_image":[{"url":"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.cakephpexpert.com\/blog\/#website","url":"https:\/\/www.cakephpexpert.com\/blog\/","name":"Cakephp Expert Blog","description":"Cakephp Development Company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cakephpexpert.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#primaryimage","inLanguage":"en-US","url":"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg","contentUrl":"http:\/\/www.cakephpexpert.com\/blog\/wp-content\/uploads\/2015\/01\/link-building-2-740x350.jpg"},{"@type":"WebPage","@id":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#webpage","url":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps","name":"Build Your First Website with CakePHP in Three Easy Steps - Cakephp Expert Blog","isPartOf":{"@id":"https:\/\/www.cakephpexpert.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#primaryimage"},"datePublished":"2015-01-26T07:28:47+00:00","dateModified":"2015-01-26T09:57:47+00:00","author":{"@id":"https:\/\/www.cakephpexpert.com\/blog\/#\/schema\/person\/0f12b00f339dcf099f8431b3ba0db2e1"},"breadcrumb":{"@id":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.cakephpexpert.com\/blog\/build-your-first-website-with-cakephp-in-three-easy-steps#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cakephpexpert.com\/blog"},{"@type":"ListItem","position":2,"name":"Build Your First Website with CakePHP in Three Easy Steps"}]},{"@type":"Person","@id":"https:\/\/www.cakephpexpert.com\/blog\/#\/schema\/person\/0f12b00f339dcf099f8431b3ba0db2e1","name":"admin","image":{"@type":"ImageObject","@id":"https:\/\/www.cakephpexpert.com\/blog\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/28e9fe1b5e695a0ed4f8d10cb1186b26?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28e9fe1b5e695a0ed4f8d10cb1186b26?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/www.cakephpexpert.com\/"],"url":"https:\/\/www.cakephpexpert.com\/blog\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/posts\/544"}],"collection":[{"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/comments?post=544"}],"version-history":[{"count":7,"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/posts\/544\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/posts\/544\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/media?parent=544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/categories?post=544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cakephpexpert.com\/blog\/wp-json\/wp\/v2\/tags?post=544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}