Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
$blogPosts = array(
1 => array(
'date' => '2011-03-29',
'author' => 'igorw',
'title' => 'Using Silex',
'body' => '...',
),
);
$app->get('/blog', function() use ($blogPosts) {
$output = '';
foreach ($blogPosts as $post) {
$output .= $post['title'];
$output .= '<br />';
}
return $output;
});
require_once "views/template.php"; пойдет? Понятие «по-правильному» вы определяете для себя сами, исходя из требований разрабатываемого приложения.function render($template, array $data) {
foreach ($data as $key => $value) {
$$key = $value;
ob_start();
require __DIR__ . '/../templates/' . $template;
return ob_get_clean();
}
и пишите что-то вроде$app->get('/blog', function() use ($blogPosts) {
$posts = $blogPosts; // тут может быть формирование массива из БД
return render('../templates/blog.php', array('posts' => $posts));
});, где templates/blog.php что-то вроде<?php foreach ($posts as $post): ?>
<?php echo $post['title'] ?></br>
<?php endfor ?>
require 'sinatra'
get '/hi' do
"Hey there!"
end
require и у вас уже 2 файла. В чем проблема?
require_once('glue.php');
$urls = array(
'/' => 'index',
'/(\d+)' => 'index'
);
class index {
function GET($matches) {
if ($matches[1]) {
echo "The magic number is: " . $matches[1];
} else {
echo "You did not enter a number.";
}
}
}
glue::stick($urls);
suhosin.executor.include.whitelist = phar в suhosin.ini
Silex — микрофреймворк от создателей Symfony2