我刚开始使用 PHP 框架锂 (v 0.10)。
我遵循了使用 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
我的Posts.php
模型/app/models
:
<?php
namespace app\models;
class Posts extends \lithium\data\Model {
}
?>
我的PostsController.php
控制器在/app/controllers
:
<?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
在/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; ?>