donglei1616
donglei1616
2014-04-11 16:00

CakePHP正确的语法来打印输出变量

I have a beginners question about CakePHP. I'm trying to print out data I got from database to view but I cannot figure out correct syntax how to do it. I have variable $title in the view.ctp in which there are data I need to print out. I used debug on the $title variable and I got this print out:

array(
    (int) 0 => array(
        'posts' => array(
            'title' => 'The title'
        )
    )
)

But when I try to print out just the title ('The title'), it gives me an error:

Notice (8): Undefined index: posts [APP/View/Posts/view.ctp, line 3]

To print out the title I'm using:

echo h($title['posts']['title']);

What's the correct way to do it? Thanks in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • doushang4274 doushang4274 7年前
    <?php 
    
    if(isset($title)){
        echo ($title[0]['posts']['title']);
    } 
    
    ?>
    
    点赞 评论 复制链接分享
  • dongling0519 dongling0519 7年前

    Try:

    echo h($title[0]['posts']['title']);
    
    点赞 评论 复制链接分享

相关推荐