Skip to content

Commit

Permalink
merged changes from screencast
Browse files Browse the repository at this point in the history
  • Loading branch information
walterdavis committed Nov 3, 2010
1 parent b814245 commit 3948963
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
9 changes: 6 additions & 3 deletions scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ function save(){
';
}
}
foreach($_POST['habtm'] as $k => $v){
if($v > 0){
$code .= ' foreach($this->find_attached(\'' . $k . '\') as $a) $this->detach($a);
if(isset($_POST['habtm'])){
foreach($_POST['habtm'] as $k => $v){
if($v > 0){
$code .= ' foreach($this->find_attached(\'' . $k . '\') as $a) $this->detach($a);
';
}
}
}
$code .= "\t\treturn parent::destroy();\n\t}\n";
Expand Down Expand Up @@ -234,6 +236,7 @@ function copy_file($source, $dest, $mode = 0664){
$out .= copy_file('MyActionView.php',$db . '/_app/lib/MyActionView.php');
$out .= copy_file('application.css',$db . '/css/application.css');
$out .= copy_file('inflector.php',$db . '/_app/lib/inflector.php');
$out .= copy_file('helpers.php',$db . '/_app/helpers/helpers.php');
$out .= copy_file('inflections.php',$db . '/_app/lib/inflections.php');
$out .= copy_file('/images/favicon.ico',$db . '/favicon.ico');
$out .= create_file($db . '/_app/views/' . $table_name . '/create.html.php',$view_create);
Expand Down
1 change: 1 addition & 0 deletions templates/MyActionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function link_to($strText, $strAction, $object, $html = array()){
return '<a href="' . MyActionView::url_for($strAction, $object) . '"' . $html_extras . '>' . $strText . '</a>';
}
function url_for($strAction,$object){
if(substr($strAction,0,1) == '/') return $strAction;
$controller = strtolower(get_class($object));
$link = "/" . $controller . "/" . $strAction;
if($object->id > 0 && $strAction != "index" && $strAction != "create") $link .= "/" . $object->id;
Expand Down
6 changes: 5 additions & 1 deletion templates/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body, html {
#PageDiv {
width: 85%;
border: 3px solid #909090;
margin: 10px auto 14px;
margin: 10px auto 44px;
padding: 14px 20px;
background-color: #fff;
}
Expand Down Expand Up @@ -179,3 +179,7 @@ input.form_button {
.form_button.delete:hover {
background-color: #d84538;
}

.right {
float: right;
}
20 changes: 11 additions & 9 deletions templates/routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require_once('_app/lib/MyActionController.php');
require_once('_app/lib/inflector.php');
require_once('_app/lib/inflections.php');
require_once('_app/helpers/helpers.php');
class ActiveRecord extends MyActiveRecord{

}
Expand All @@ -40,16 +41,15 @@ function __autoload($class_name) {
}
if($missed == true) trigger_error('Could not load the "' . $class_name . '" class. Make sure you have generated it before trying again.', E_USER_ERROR);
}
function h($string)
{
function h($string){
return htmlentities($string,ENT_COMPAT,MYACTIVERECORD_CHARSET);
}
function t($string){
$search = array("","","","",'"');
$replace = array("'","'",'','','');
return str_replace($search,$replace,(strip_tags($string)));
}

//build automatic navigation bar
$navigation = '<ul class="navigation"><li><a href="/">Home</a></li>';
$models = scandir(APP_ROOT . '/_app/models');
foreach($models as $m){
Expand All @@ -60,12 +60,18 @@ function t($string){
}
}
$navigation .= '</ul>';
//flash messages built here
function flash($arrMessages,$strClass=''){
if(empty($strClass)) $strClass = 'flash';
$out = '<ul class="' . $strClass . '">';
foreach((array)$arrMessages as $m) $out .= '<li>' . $m . '</li>';
return $out . '</ul>';
}
//and decoded from session here
if(isset($_SESSION["flash"])){
$flash = $_SESSION["flash"];
unset($_SESSION["flash"]);
}
//routing happens here
$uri = preg_split('/\//',$_SERVER['REQUEST_URI'],-1,PREG_SPLIT_NO_EMPTY);
if(!isset($uri[0]) || empty($uri[0])){
Expand Down Expand Up @@ -93,17 +99,13 @@ function flash($arrMessages,$strClass=''){
$uri[1] = 'delete';
}
if(isset($uri[1]) && method_exists($controller,$uri[1])){
$out = $controller->{$uri[1]}($id);
$page_title .= t(' | ' . ucfirst($uri[1]) . ' ' . ucfirst($uri[0]));
$page_header = h(ucfirst($uri[1]) . ' ' . ucfirst($uri[0]));
$out = $controller->{$uri[1]}($id);
}else{
$out = $controller->index();
$page_title .= t(' | ' . ucfirst($uri[0]));
$page_header = h(ucfirst($uri[0]));
}
if(isset($_SESSION["flash"])){
$flash = $_SESSION["flash"];
unset($_SESSION["flash"]);
$out = $controller->index();
}
include(APP_ROOT . '/_app/views/layouts/index.html.php');
}elseif(!isset($uri[0])){
Expand Down

0 comments on commit 3948963

Please sign in to comment.