我是新的php。所以一个人推荐我一步一步地执行本教程 - http://symfony.com/doc/current/book/from_flat_php_to_symfony2.html(之前的章节“添加一个Symfony的触摸”)。成为好人!我创建了我的第一个博客!但是,当我尝试获取“显示”页面时,该页面显示由id查询参数标识的单个博客帖子,我的浏览器显示:“在此服务器上未找到请求的URL /读取。我不使用.htaccess和重写模式的Apache(服务器版本 - Apache/2.2.22)启用。我的代码IA未来:在此服务器上未找到请求的URL /读取
前端控制器
// index.php
// load and initialize any global libraries
require_once 'model.php';
require_once 'controllers.php';
// route the request internally
$uri = $_SERVER['REQUEST_URI'];
if ('/index.php' == $uri) {
list_action();
} elseif ('/index.php/show' == $uri && isset($_GET['id'])) {
show_action($_GET['id']);
} else {
header('Status: 404 Not Found');
echo '
Page Not Found
';}
Controllers.php
function list_action()
{
$posts = get_all_posts();
require 'templates/list.php';
}
function show_action($id)
{
$post = get_post_by_id($id);
require 'templates/show.php';
}
型号
// model.php
function open_database_connection()
{
$link = mysql_connect('localhost', 'root', 'zoob');
mysql_select_db('post', $link);
return $link;
}
function close_database_connection($link)
{
mysql_close($link);
}
function get_all_posts()
{
$link = open_database_connection();
$result = mysql_query('SELECT id, title FROM post', $link);
$posts = array();
while ($row = mysql_fetch_assoc($result)) {
$posts[] = $row;
}
close_database_connection($link);
return $posts;
}
function get_post_by_id($id)
{
$link = open_database_connection();
$id = intval($id);
$query = 'SELECT date, title, post FROM post WHERE id = '.$id;
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
close_database_connection($link);
return $row;
}
模板
//layout.php
<?php echo $title ?>//list.php
List of Posts
//show.php
$title = $post['title'] ?>
<?php echo $post['title'] ?>
请帮我解决和理解问题。谢谢
2014-11-15
Antin
+0
看起来你定义的路由/节目ID = {ID},但您的链接指向/读取ID = {ID} –
+0
哦,我改变了它'/ read?id = {id}'到'/ show?id = {id}'但存在问题! –
+0
好吧,我想你还需要确保你的链接指向/index.php/show?id={id}而不仅仅是/ show?id = {id} –