The comment list is not displayed in cakephp.

Asked 2 years ago, Updated 2 years ago, 174 views

Enter a description of the image here image

I'm studying cakephp with dot installation.
"Regarding ""View comment list"", it doesn't display correctly…
" Is there a problem with the model or is it not displayed correctly in the view...
Please tell me who it is.

US>Dot Installation Video
http://dotinstall.com/lessons/basic_cakephp/7527
http://dotinstall.com/lessons/basic_cakephp/7528

[Comment.php]

<?php

class Comment extensions AppModel {
    public$belongsTo='Post';
}

?>

[Post.php]

<?php

class Post extensions AppModel {
    public$hasMany='Comment';

    public$validate=array(
        'title' = > array(
            'rule' = > 'notEmpty',
            'message' = > 'empty'
        ),
        US>'body'=>array(
            'rule' = > 'notEmpty'
        )
    );
}

?>

[view.ctp]

<h2><?phpechoh($post['Post']['title']);?>/h2>

<p><?phpechoh($post['Post']['body']);?>/p>

<h2>Comments<h2/>
<ul>
<?php foreach ($post['Comment'] as $comment): ?>
<li><?phpechoh($comment['body'])?>by<?phpechoh($comment['comment']);?></li>
<?php endforeach;?>
</ul>

php cakephp dotinstall

2022-09-30 20:34

2 Answers

I think there is a problem with the data in DB because the results are empty in SQL to retrieve comments.

The screenshot of the question appears to be an article with id=1.

When entering data into the comments table in the "#26 Comments table" of the series, the SQL code that matches post_id as 7 by saying "If you look at the contents of the DB, let's make it 7."

As you can see in the video, post_id=7 data was entered, so I thought I couldn't get a comment. What do you think?

Reference

Association: Connecting Models—CakePHP Cookbook 2.x Documentation


2022-09-30 20:34

The number of lines (Num.rows) in Query Nr.2 in the screenshot is 0, so there is no data in the comments table.


2022-09-30 20:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.