PHP フレームワークのリチウム (v 0.10) を使い始めたところです。MongoDB をデータベースとして使用するクイック スタート マニュアル
に従いました。
リチウムについてもう少し詳しく知るために、DBMS を MonogoDB から MySQL に切り替えたいと思いました。
私が抱えている問題/posts/
は、ブラウザ リチウムで開いたときにエラー メッセージのない空白のページしか表示されないことです。また、に行くと/posts/add/
正しいフォームが表示されますが、データを送信した後 (DB に正しく書き込まれます)、リチウムも空白のページを表示するだけです。何がうまくいかないのですか?
また、リチウムのモデルに関するリチウムのドキュメントを読んだ後でも、どのロジック (この場合) がモデルに属しているかはまだよくわかりません。
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
posts
行id
、title
およびを含む MySQL テーブルを手動でセットアップしました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; ?>