Skip to content

Commit

Permalink
Adding auto rendering features
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice Luraine committed Feb 21, 2010
1 parent 3a6534a commit 08973e7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TODO
@@ -1,8 +1,8 @@
# TODO #

- testing and documenting autorendering features
- adding an option('display_errors'); by default ini_set('display_errors', 0) in production env, but enabled if env is dev (unless matching option is enabled)
- explain autoload_controller() in README
- doc before($route)
- in debug output, formating debug_backtrace to be me readable (like debug_backtrace output but with extra informations that can be toggled)
- #36, explicit HTTP/1.1
- adding tests with special characters for request_uri
Expand Down
32 changes: 32 additions & 0 deletions examples/example04/index.php
@@ -0,0 +1,32 @@
<?php
# Autorendering example

require_once dirname(dirname(dirname(__FILE__))).'/lib/limonade.php';

function configure()
{
option('env', ENV_DEVELOPMENT);
option('autorender', true);
}

dispatch('/', 'index');
function index()
{
return "is rendering something";
}

dispatch('/no', 'no_output');
function no_output()
{
// rendering nothing;
// return null;
}


function autorender($route)
{
// check $route['function'] and call the matching view to render
return "My view called by autorendering.";
}

run();
1 change: 1 addition & 0 deletions examples/index.php
Expand Up @@ -15,6 +15,7 @@
<li><a href="example01/">example 01: Hello World!</a></li>
<li><a href="example02/">example 02: errors</a></li>
<li><a href="example03/">example 03: routes with options, and conditional before function</a></li>
<li><a href="example04/">example 04: autorendering example</a></li>
<li><a href="urlrewrite/"> Url Rewriting with Limonade.</a></li>
</ul>
</body>
Expand Down
8 changes: 4 additions & 4 deletions lib/limonade.php
Expand Up @@ -329,6 +329,7 @@ function run($env = null)
option('session', LIM_SESSION_NAME); // true, false or the name of your session
option('encoding', 'utf-8');
option('gzip', false);
option('autorender', false);
option('x-sendfile', 0); // 0: disabled,
// X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
// X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
Expand Down Expand Up @@ -405,10 +406,9 @@ function autoload_controller($callback)
call_if_exists('before', $route);

# 6.4 Call matching controller function and output result
if($output = call_user_func_array($route['function'], array_values($route['params'])))
{
echo after(error_notices_render() . $output, $route);
}
$output = call_user_func_array($route['function'], array_values($route['params']));
if(is_null($output) && option('autorender')) $output = call_if_exists('autorender', $route);
echo after(error_notices_render() . $output, $route);
}
else halt(SERVER_ERROR, "Routing error: undefined function '{$route['function']}'", $route);
}
Expand Down

0 comments on commit 08973e7

Please sign in to comment.