Creating a site from scratch

From Rhypedigital

Jump to: navigation, search

Contents

[edit] Assumptions

  • Domain name is registered
  • vhost is setup to point to a directory
  • logging is setup to a log directory
  • PHP is working correctly
  • MySQL database is being used

[edit] Our example site

Example site 'learn.riphplib.org' found at learn.riphplib.org

Directory structure:

/home2/rhype/hosting/learn.riphplib.org

logs
dev
   RiPHPLib -> link to where ever shared RiPHPLib is located
   Lib
      View
      Component
   Ctrl
   Skeleton
      View
      Component


dev is the source directory and should have a relevant vhost associated with it.

[edit] Switcher

The site needs a switcher file which determines what to do. This file is called everytime the site is accessed. It will be called index.php or whatever your default document is configured as.

Here is a basic switcher index.php


[edit] Our first page

Our first web page is comprised of a skeleton, view and a controller.

  • Our first Skeleton A skeleton is a html template with optional placeholders that is used by the View. It is located in Skeleton/View and usually tightly coupled to the View itself.
  • Our first View A View is code used to render the web page. The view controls the presentation of the data. View files are located in Lib/View in order to maintain a similar path structure to the skeletons.
  • Our first controller A controller is the main part of the web page. It takes input from the user and decides what to do with it.

Viewing the page:

Url http://learn.riphplib.org/index.php?script=Message will now run the Message controller page.

If the controller was called Index.php then the switcher 'index.php' would load it by default.

[edit] Connecting to the database

Create a database and make sure you can connect using mysql client.

Now edit Lib/Config.php and update the database parameters. Here is an example Config.php

Uncomment the database connection and commit lines from the switcher.

Re-test the message page and it should still work.


We now need to generate active record classes which allow us to manipulate the database very easily.

From the website root directory run ./RiPHPLib/Auto/ARGen.php

Now check in Lib/Model/AR which should contain a file for each table in your database. This will need to be executed everytime you change the database structure.


[edit] Our first database page

Our database connected web page is comprised of a skeleton, view, model and a controller. It is called Test.

  • Our First DB Skeleton This skeleton has a repeater in to allow displaying of data from multiple rows. It also has more placeholders to represent the fields in the table.
  • Our First DB View This file now creates a control for each field placeholder in the skeleton. It also takes in a model as a parameter and binds it to the controls.
  • Our First DB Model This file is responsible for retrieving the data from the database. In this case the model is the auto-generated Active Record class from above.
  • Our First DB Controller This controller creates the model (active record) and decides which records to display. In this case all records are displayed.


[edit] Components

Components are reuseable mini-views. They are created in the controller and may or may not use models in the same way as a view may or may not.

A component does not use a model to directly update data. Instead, a model is passed into a component for it to popuplate with data. The controller then tells the model to update the underlying data storage.

We will create a component to insert records into our test database. The component is called Insert and is located in Lib/Component. It will be used by a controller called Updater which will use an 'Updater' view and skeleton.

Personal tools