Page Controller Tutorial

From Photon Framework

Jump to: navigation, search

Contents

Overview

In this tutorial we will cover how to quickly create the basic page controller for your website. This particular tutorial uses the PTagViewRenderer to dynamically load templates, which is not the easiest page controller that Photon offers. There is also the PhpViewRenderer which may be of more interest to you if you're just starting your Photon experience.

Setting Up Apache

The first thing that we should do before we actually start our project is set-up Apache to be a page controller. We're going to make a virtual host, and were going to set some options to make sure that things are running correctly. With Photon, apache will serve up a website using the virual host for example: http://example. Once we hit that website Photon will take over and decide what we need to load: http://example/admin will load the index.php for the admin area of our website.

1. The first step is to make sure that you actually have the apache module mod_rewrite enabled. You might have to alter your apache config to make sure that its there and functioning.

2. Next we want to add our virtual host mine looks like this:

 <VirtualHost *:80>
         ServerAdmin webmaster@localhost
         ServerName mpc
         Options -execCGI
         CustomLog /var/log/mpc-access.log combined
         ErrorLog /var/log/mpc_error.log
         DocumentRoot /var/www/mpc/
         RewriteEngine On
         RewriteRule ^/([^.]+)$ /index.php/ [NC,L]
 </VirtualHost>

The most important part of the virtual host is the ServerName and RewriteRule. The server name is what we will type into our browser to actuall hit our Photon project. The rewrite rule (which you can just copy from above if you want) will rewrite all URLs that do not being with a '.' this will make it so we can include files on a relative path still.

3. (Some Machines) Certain operating systems will require that you edit the Hosts file. This is basically adding another host so it knows when you type in: example that you're actually going to go check locally first before running out to the internet. Mine looks like this:

 127.0.0.1     mpc

Easy enough!

Creating Our Project

Testing Our Project