a tiny mvc framework for php using php-activerecord
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add flash_success and add_flash_successes(), like errors and notices

make notices print blue by default now, and successes in green

+54 -8
+10
lib/controller.php
··· 147 147 array_push($_SESSION["flash_notices"], $string); 148 148 } 149 149 150 + /* store a success message in the session to be printed on the next view 151 + * with the flash_success() helper */ 152 + public function add_flash_success($string) { 153 + if (!isset($_SESSION["flash_successes"]) || 154 + !is_array($_SESSION["flash_successes"])) 155 + $_SESSION["flash_successes"] = array(); 156 + 157 + array_push($_SESSION["flash_successes"], $string); 158 + } 159 + 150 160 /* cancel all buffered output, send a location: header and stop processing */ 151 161 public function redirect_to($obj_or_url) { 152 162 $link = HTMLHelper::link_from_obj_or_string($obj_or_url);
+19
lib/helpers/html_helper.php
··· 108 108 return $html; 109 109 } 110 110 111 + /* print the successes stored in the session and then reset the array */ 112 + public function flash_successes() { 113 + $html = ""; 114 + 115 + if (isset($_SESSION["flash_successes"]) && 116 + count((array)$_SESSION["flash_successes"])) { 117 + $html = "<div class=\"flash-success\">" 118 + . implode("<br />\n", array_map(function($e) { 119 + return raw_or_h($e); }, 120 + (array)$_SESSION["flash_successes"])) 121 + . "</div>"; 122 + 123 + /* clear out for the next view */ 124 + $_SESSION["flash_successes"] = array(); 125 + } 126 + 127 + return $html; 128 + } 129 + 111 130 /* create a link to a javascript file, appending its modification time to 112 131 * force clients to reload it when it's modified */ 113 132 public function javascript_include_tag($files) {
+8 -1
lib/utilities.php
··· 143 143 144 144 /* when passed a closure containing print/<?=?> code, execute it, capture the 145 145 * output, and return it as a string */ 146 - static function to_s($obj, $closure) { 146 + static function to_s($obj, $closure, $bind = null) { 147 147 ob_start(); 148 + 149 + if (version_compare(PHP_VERSION, "5.4.0") >= 0) 150 + /* setup $this */ 151 + if (!empty($bind)) 152 + $closure->bindTo($bind); 153 + 148 154 $closure($obj); 155 + 149 156 $str = ob_get_contents(); 150 157 ob_end_clean(); 151 158
+16 -7
skel/public/stylesheets/application.css
··· 1 1 /* application css */ 2 2 3 - /* for flash_notices() and flash_errors() */ 4 - div.flash-notice, div.flash-error { 3 + /* for flash_errors(), flash_notices() and flash_successes() */ 4 + div.flash-error, 5 + div.flash-notice, 6 + div.flash-success { 5 7 border: 2px solid; 6 8 margin: 5px 5px 10px 5px; 7 9 padding: 5px 10px; 8 10 } 9 11 10 - div.flash-notice { 12 + div.flash-error { 13 + background-color: #ffe7e7; 14 + border-color: red; 15 + } 16 + 17 + div.flash-success { 11 18 background-color: #e8ffe7; 12 19 border-color: green; 13 20 } 14 21 15 - div.flash-error { 16 - background-color: #ffe7e7; 17 - border-color: red; 22 + div.flash-success { 23 + background-color: #e0e2fc; 24 + border-color: blue; 18 25 } 19 26 20 27 /* for error_messages_for() */ ··· 22 29 display: inline; 23 30 } 24 31 25 - div.fieldWithErrors input, div.fieldWithErrors select { 32 + div.fieldWithErrors input, 33 + div.fieldWithErrors select, 34 + div.fieldWithErrors textarea { 26 35 border: 2px solid red; 27 36 padding: 2px; 28 37 }
+1
skel/views/layouts/application.phtml
··· 9 9 </head> 10 10 <body> 11 11 <?php echo $html->flash_errors(); ?> 12 + <?php echo $html->flash_successes(); ?> 12 13 <?php echo $html->flash_notices(); ?> 13 14 14 15 <?php echo $content_for_layout; ?>