【发布时间】:2011-08-09 11:21:17
【问题描述】:
我刚开始使用 PHP 框架锂 (v 0.10)。
我关注了the quick start manual,它使用 MongoDB 作为数据库。
为了进一步了解锂,我想将 DBMS 从 MonogoDB 切换到 MySQL。
当我在浏览器锂中打开/posts/ 时遇到的问题只显示一个没有错误消息的空白页面。另外,当我去/posts/add/时,会显示正确的表单,但是在提交数据(正确写入数据库)后,锂也只是显示一个空白页。怎么了?
另外,在阅读了有关锂模型的锂文档后,我仍然不太确定模型(在这种情况下)属于什么逻辑。
UPDATE 1:
我看起来 APC 缓存有问题。安装 APC 并重命名包含锂的文件夹后,该应用程序可以正常运行。保留包含锂的文件夹名称不变时,出现缓存错误:
Warning: include(/var/www/web/frameworks/lithium/app/resources/tmp/cache/templates/template_views_layouts_default.html_886_1308416958_798.php) [function.include]: failed to open stream: No such file or directory in /var/www/web/frameworks/lithium/libraries/lithium/template/view/adapter/File.php on line 111
Warning: include() [function.include]: Failed opening '/var/www/web/frameworks/lithium/app/resources/tmp/cache/templates/template_views_layouts_default.html_886_1308416958_798.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/web/frameworks/lithium/libraries/lithium/template/view/adapter/File.php on line 111
END UPDATE 1
我手动设置了一个 MySQL 表 posts,其中包含 id、title 和 body 行。
/app/models 中的我的 Posts.php 模型:
<?php
namespace app\models;
class Posts extends \lithium\data\Model {
}
?>
/app/controllers 中的我的 PostsController.php 控制器:
<?php
namespace app\controllers;
use app\models\Posts;
class PostsController extends \lithium\action\Controller {
public function index() {
$posts = Posts::all();
return compact('posts');
var_dump($posts);
}
public function add() {
if($this->request->data) {
$post = Posts::create($this->request->data);
$success = $post->save();
}
return compact('success');
}
}
?>
最后是我对index.html.php 在/app/views/posts/ 中的看法:
<?php foreach($posts as $post): ?>
<article>
<h1><?=$post->title ?></h1>
<p><?=$post->body ?></p>
</article>
<?php endforeach; ?>
还有add.html.php in /app/views/posts/:
<?=$this->form->create(); ?>
<?=$this->form->field('title');?>
<?=$this->form->field('body', array('type' => 'textarea'));?>
<?=$this->form->submit('Add Post'); ?>
<?=$this->form->end(); ?>
<?php if ($success): ?>
<p>Post Successfully Saved</p>
<?php endif; ?>
【问题讨论】:
-
你得到什么错误或者根本没有得到什么错误,试试 var_dump($posts) ?
-
@jurka:根本没有。 Chrome 只显示带有
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection. No Data was sent by the server.的错误页面
标签: php mysql frameworks lithium