So with a little help I was able to get my first mvc framework up and running locally. Now that I've put it up on the server I'm not having any luck. I believe it's a configuration issue but I can't seem to figure it out.
Here's a Gif of what it should look like on the server but this is running it locally.
I used a Rewrite file but my friend helped me with it so I don't fully understand what it is doing. I read the RewriteBase documentation as well as the Apache mod_rewrite documentation but am still pretty confused. So with these in mind:
Could someone please help me understand this Rewrite file a little more.
ie:
- How does %{REQUEST_FILENAME} work/what does it do and how does it work with the RewriteRule for both !-f and !-f?
- What does [NC, L] do?
What I know:
- '-d' (is directory)
Treats the TestString as a pathname and tests whether or not it exists, and is a directory.
- '-f' (is regular file)
Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [NC,L]
tinyMvc.php (application/tinyMvc.php)
(Please ignore the fact that this is named tinyMvc. It has nothing to do with tinyMvc.)
<?php
include_once 'load.php';
// require_once '../../webconfig.php';
// include_once 'models/model.php';
// include_once 'controllers/controller.php';
// Local
// define ('URL_ROOT', 'http://localhost/');
// Remote
define ('URL_ROOT', 'http://tomcat.cit.ipui.edu/alecory/Spring-2014/Assignment%202/');
// define ('URI', $_SERVER['REQUEST_URI']);
// Outputs for:
// Local = /register (ex: register form)
// Remote = /alecory/Spring-2014/CIT-31300/Assignment%202/views/register.php
define('URI', '/register'); // <= this is where I could set it myself and it would
# reroute the URL from
# /Assignment%202/views/register.php To
# /Assignment%202/
# (only showing /Assignment%202/ in the URL)
define ('DOC_ROOT', $_SERVER['DOCUMENT_ROOT']);
// Local = /Applications/MAMP/htdocs/CIT-31300/Assignment 2 (ex: register form)
// Remote = /var/www/ (ex: register form)
function autoloader($class)
{
include_once strtolower($class) . 's/' . $class . '.php';
}
spl_autoload_register('autoloader');
new Controller();
?>
controller.php (application/controllers/controller.php)
class Controller
{
public $load;
public $model;
function __construct()
{
// Make
$this->load = new Load();
$this->model = new Model();
// Set the $page = current view/page
$page = ltrim(URI, '/');
// Set default page to index
if (empty($page))
{
$page = 'index';
}
// Load the Pages
if (method_exists($this, $page))
{
// die(get_include_path());
require_once DOC_ROOT . '/views/inc/header.php';
$this->$page();
require_once DOC_ROOT . '/views/inc/footer.php';
}
else
{
require_once DOC_ROOT . '/views/inc/header.php';
$this->notFound();
require_once DOC_ROOT . '/views/inc/footer.php';
}
}
// Functions to load the various views
function index()
{
// $data = $this->model->my_user_info();
$this->load->view('myview.php', $data);
}
function login()
{
$this->load->view('login.php', $data);
}
function register()
{
$this->load->view('register.php', $data);
}
function notFound()
{
die('not found');
}
}
?>