我正在创建评论表。因此,RedBean创建了一个表,但是没有填充信息
我的代码
if (isset($_POST['send'])) {
$comments = R::dispense('comments');
var_dump($comments);
$comments['id'] = $_GET['id'];
$comments->firstName = $_SESSION['first_name'];
$comments->lastName = $_SESSION['last_name'];
$comments->message = $_POST['message'];
$comments->avatar = $_SESSION['avatar'];
R::store($comments);
我的表格
<form action="" id="commentForm" method="post">
<div class="col-md-6">
<input type="text" placeholder="Ваш комментарий" class="mb-3 mt-3 form-control" name="message" minlength="5" required>
</div>
<div class="col-md-6" style="margin-bottom: 1rem;">
<input type="submit" class="btn btn-primary" name="send">
所有字段均已填写,但我不希望如此
答案 0 :(得分:1)
//这样定义映射
define( 'POEM', 'tbl_poem' );
define( 'BOOK', 'tbl_book' );
define( 'AUTHOR', 'tbl_author' );
define( 'CATEGORY', 'tbl_category' );
define( 'POEMS', 'ownTblPoem' );
define( 'CATEGORIES', 'sharedTblCategory' );
//Create an extension to by-pass security check in R::dispense
R::ext('xdispense', function( $type ){
return R::getRedBean()->dispense( $type );
});
//Use tbl_book_category instead of tbl_book_tbl_category
R::renameAssociation([
'tbl_book_tbl_category' => 'tbl_book_category'
]);
//Use them like this:
$poem = R::xdispense( POEM );
$poem->title = 'Trees';
$author = R::xdispense( AUTHOR );
$author->name = 'Joyce Kilmer';
$book = R::xdispense( BOOK );
$book->title = 'Trees and other poems';
$category = R::xdispense( CATEGORY );
$category->name = 'nature';
$book->{AUTHOR} = $author;
$book->{POEMS}[] = $poem;
$book->{CATEGORIES}[] = $category;
$id = R::store( $book );
//For testing purposes let's output something:
$book = R::load( BOOK, $id );
$poem = reset( $book->{POEMS} );
$author = $book->{AUTHOR};
$category = reset( $book->{CATEGORIES} );
echo "Have you ever read '{$poem->title}' ({$book->title}) by {$author->name} ?
it's a beautiful poem about {$category->name}.";