Skip to content

IT-Academy-BCN/phpInitialDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP initial Project

Main structure of php project. Folders / files:

  • app
    • controllers
    • models
    • views
  • config
  • lib
    • base
  • web

Usage

The web/index.php is the heart of the system. This means that your web applications root folder is the “web” folder.

All requests go through this file and it decides how the routing of the app should be. You can add additional hooks in this file to add certain routes.

Project Structure

The root of the project holds a few directories: /app This is the folder where your magic will happen. Use the views, controllers and models folder for your app code. /config this folder holds a few configuration files. Currently only the connection to the database. /lib This is where you should put external libraries and other external files. /lib/base The library files. Don’t change these :) /web This folder holds files that are to be “downloaded” from your app. Stylesheets, javascripts and images used. (and more of course)

The system uses a basic MVC structure, with your web app’s files located in the “app” folder.

app/controllers

Your application’s controllers should be defined here.

All controller names should end with “Controller”. E.g. TestController. All controllers should inherit the library’s “Controller” class. However, you should generally just make an ApplicationController, which extends the Controller. Then you can defined beforeFilters etc in that, which will get run at every request.

app/models

Models handles database interaction etc.

All models should inherit from the Model class, which provides basic functionality. The Model class handles basic functionality such as:

Setting up a database connection (using PDO) fetchOne(ID) save(array) → both update/create delete(ID) app/views Your view files. The structure is made so that having a controller named TestController, it looks in the app/views/test/ folder for it’s view files.

All view files end with .phtml Having an action in the TestController called index, the view file app/views/test/index.phtml will be rendered as default.

config/routes.php

Your routes around the system needs to be defined here. A route consists of the URL you want to call + the controller#action you want it to hit.

An example is: $routes = array( ‘/test’ => ‘test#index’ // this will hit the TestController’s indexAction method. );

Error handling

A general error handling has been added.

If a route doesn’t exist, then the error controller is hit. If some other exception was thrown, the error controller is hit. As default, the error controller just shows the exception occured, so remember to style the error controller’s view file (app/views/error/error.phtml)

Utilities

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published