Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I like your thinking. I had a look at CodeIgniter, Cake and the other frameworks and whilst they were good I decided to write my own. I learnt a ton. The first revision of my framework wasn't that great but I have two sites running on that without issues. The second edition of it might not be as mature as Cake etc but it makes building PHP apps a breeze and the key thing for me is: <em>I know what every line of code does and it's super-quick to change and debug</em>.</p> <p>I think the first thing to do is to think about how you are going to break the app into layers, obvious candidates are:</p> <ul> <li>Front Controller: A class that parses URLs and decides what to do with them. Most frameworks these days use an Apache mod-rewrite rule to forward all URLs to one class - so it's a single entry point into your app.</li> <li>Database abstraction layer: Put all of your code that read/writes to a DB in one place and have everything call that. Also known as ORM.</li> <li>Models: Classes that represent one or more tables from your DB.</li> <li>Controllers: Classes that update/read models, apply logic and populate and show views.</li> <li>Views: HTML files that import data from your controllers. I use Smarty.</li> </ul> <p>So taking those elements, you have a basic directory structure:</p> <pre><code>/models /controllers /includes /views /css /js index.php </code></pre> <p>index.php is my Front Controller. And I put ORM stuff and other helper classes for doing generic work like processing forms and stuff into the /includes directory. Obviously /css and /js houses your static javascript and CSS files.</p> <p>The Front Controller works in that you have URLs that specify which controller to create - something like: www.domain.com/product/1/hello-world. Where product is the name of a class (I call my controllers Controller) - so here my front controller would read the product part of the URL and create an instance of ProductController. </p> <p>The controllers act upon the rest of the URL that they are given. So ProductController gets params of 1 and hello-world. 1 could be the index of a product to load and display. hello-world is just SEO text to ignore. You could also specify functions to call, so www.domain.com/product/list - this time you create a ProductController and call the list function.</p> <p>There's different ways to structure a MVC app and forums are full of arguments about it - what I've put above my or may not be true MVC but the main goal is to get good abstraction into your app. </p> <p>I'd recommend checking out Smarty for your View layer. It's a stable library and provides HTML caching as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload