Permalink
Browse files

use baseurl setting from config to keep urls tight

  • Loading branch information...
1 parent 6b29240 commit 745fcf1a86d546225ca4ddc439e6ae3ffbb4b83e @beezee committed Apr 7, 2012
Showing with 21 additions and 11 deletions.
  1. +3 −1 bootstrap.php
  2. +2 −1 config.php
  3. +2 −0 index.php
  4. +7 −3 lib/baseModel.php
  5. +2 −4 lib/router.php
  6. +5 −2 views/modelList.tpl
View
@@ -10,6 +10,8 @@
require_once 'config.php';
+$app->baseurl = $baseurl;
+
R::setup("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpw);
//discover and register models
@@ -35,7 +37,7 @@
require_once $filename;
foreach($classes as $class)
{
- $model = new $class();
+ $model = new $class($app);
if (isset($model->properties) and is_array($model->properties) and !empty($model->properties)) $app->registerModel($class, $model);
}
}
View
@@ -3,4 +3,5 @@
$dbhost = 'localhost';
$dbname = '';
$dbuser = '';
-$dbpw = '';
+$dbpw = '';
+$baseurl = 'http://localhost/mpmvc/';
View
@@ -2,6 +2,8 @@
require_once('lib/mpMVC.php');
+global $app;
+
$app = new mpMVC();
require_once('bootstrap.php');
View
@@ -7,6 +7,8 @@ class mpMVCModel
public function __construct()
{
+ global $app;
+ $this->app = $app;
$this->name = get_class($this);
$this->scaffold = true;
}
@@ -89,7 +91,8 @@ public function renderList()
->replace('property', '')
->replace('propVal', $model->{$this->toString})
->replace('plural', $this->plural)
- ->replace('toString', $model->{$this->toString});
+ ->replace('toString', $model->{$this->toString})
+ ->replace('base_url', $this->app->baseurl);
}
return $items;
}
@@ -104,12 +107,13 @@ public function renderItem($id)
{
$props .= $tpl->copy('property')->replace('propName', $prop)->replace('propVal', $model->$prop);
}
- return $tpl->copy('item')
+ return $tpl
->replace('id', $model->id)
->replace('property', '')
->replace('propVal', $model->{$this->toString})
->replace('plural', $this->plural)
->replace('toString', $model->{$this->toString})
- ->replace('property', $props);
+ ->replace('property', $props)
+ ->replace('base_url', $this->app->baseurl);
}
}
View
@@ -46,8 +46,7 @@ public function modelCreate()
$newModel->$key = $val;
}
$id = $model->store($newModel);
- F3::set('PARAMS["model"]', $model->plural);
- $this->modelList();
+ F3::reroute($app->baseurl.$model->plural.'/all');
}
public function modelEdit()
@@ -72,8 +71,7 @@ public function modelUpdate()
$instance->$key = $val;
}
$model->store($instance);
- F3::set('PARAMS["model"]', $model->plural);
- $this->modelList();
+ F3::reroute($app->baseurl.$model->plural.'/all');
}
public function modelView()
View
@@ -1,7 +1,10 @@
+<!-- all_link -->
+ <a class="all" href="<!-- base_url --><!-- /base_url --><!-- plural --><!-- /plural -->/all">All <!-- plural --><!-- /plural --></a>
+<!-- /all_link -->
<!-- item -->
<div>
- <h4><a href="../<!-- plural --><!-- /plural -->/<!-- id --><!-- /id -->"><!-- toString --><!-- /toString --></a></h4>
- <a class="del" id="<!-- id --><!-- /id -->">Remove</a> <a class="edit" href="../<!-- plural --><!-- /plural -->/<!-- id --><!-- /id -->/edit">Edit</a>
+ <h4><a href="<!-- base_url --><!-- /base_url --><!-- plural --><!-- /plural -->/<!-- id --><!-- /id -->"><!-- toString --><!-- /toString --></a></h4>
+ <a class="del" id="<!-- id --><!-- /id -->">Remove</a> <a class="edit" href="<!-- base_url --><!-- /base_url --><!-- plural --><!-- /plural -->/<!-- id --><!-- /id -->/edit">Edit</a>
<br />
<!-- property -->
<p><!-- propName --><!-- /propName -->: <!-- propVal --><!-- /propVal --></p>

0 comments on commit 745fcf1

Please sign in to comment.