0

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

postsidtitleおよびを含む 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; ?>
4

1 に答える 1

3

いくつかのヒント...

1) Lithium は一般的に正しく動作していますか? あなたの実際の質問/問題が何であるかについて混乱しています。

2) PostsController を変更する必要はありませんPosts::all();Posts::find('all');

3) 投稿のモデルを変更する必要がある場合があります。Lithium (MySQLを使用) は、キーとして使用するテーブル内のid列を想定します。idという名前の列がない場合は、モデルに追加する必要がある場合があります。 .

たとえば、postidtitlebodydateなどの列を持つテーブルがある場合、これをモデルに追加します

<?php
 namespace app\models;

 class Posts extends \lithium\data\Model { 
   public $_meta = array('key' => 'postid');        
 }

?>

'key' => 'postid' に注意してください。これにより、 idを探す代わりにpostidをテーブルのキーとして使用することが Lit に通知されます。

4) コントローラーで実際に MySQL クエリを作成する方法は次のとおりです ...

public function locations($companyid,$state=null) {

 /* removes null or false values with array_filter() */
 $conditions = array_filter(array('companyid' => $companyid, 'state' => $state));

 /* pass $conditions array to the Locations model, find all, order by city */
 $locations = Locations::find('all', array( 
       'conditions' => $conditions,
       'order' => array('city' => 'ASC')
 ));

 return compact('locations');

}

詳細については、Lithium マニュアルをご覧ください: http://li3.me/docs/manual

モデル

http://li3.me/docs/manual/working-with-data/using-models.md

コントローラー

http://li3.me/docs/manual/handling-http-requests/controllers.md

ビュー

http://li3.me/docs/manual/handling-http-requests/views.md

于 2011-08-12T08:00:07.890 に答える