简体   繁体   English

如何在同一页面上显示评论? cakephp

[英]how to display the comments on the same page? cakephp

I am starting to learn PHP framework, particulary cakephp. 我开始学习PHP框架,尤其是cakephp。 I know how to insert into database, but I am curious about displaying the entries on the same page. 我知道如何插入数据库,但对在同一页面上显示条目感到好奇。 I don't want to reload or redirect the page just to display the results. 我不想重新加载或重定向页面只是为了显示结果。

I have only three four fields in the database. 我在数据库中只有三个四个字段。 id, name, email, and the date. ID,名称,电子邮件和日期。 I have used the same validation in the model page. 我在模型页面中使用了相同的验证。

Controllers: 控制器:

<?php
function index(){
 if($this->request->is('Post')){
   $this->Save->save(data);
 }
 //display the entries from the database
 $this->set('saves', $this->Save->find('all'));
}
?>

Index.ctp: Index.ctp:

<?php
echo $this->Form->create('Save');
echo $this->Form->input('name', array('class'=>'name', 'required' => true));
echo $this->Form->input('email', array('class'=>'email',  'required' => true));
echo $this->Form->input('message', array( 'required' => true)); 
echo $this->Form->submit('submit', array('formnovalidate' => true));

//i want to display the entries here
foreach($saves as $row){
  echo $row['Save']['name'];
  echo $row['Save']['comment']; 
}
?>

The problem is that , it affects the textarea. 问题是,它会影响文本区域。 It reduces the size to half. 它将尺寸减小一半。 Need help. 需要帮忙。 thanks a lot. 非常感谢。 I am new to cakephp and I have been googling about it, but have not find the any results. 我是Cakephp的新手,我一直在搜索它,但未找到任何结果。 Thanks 谢谢

From what I understand it seems that your problem is more CSS issue than CakePHP issue. 据我了解,似乎您的问题更多是CSS问题,而不是CakePHP问题。 I don't think printing the data will cut the field into half. 我认为打印数据不会将字段减少一半。

Try put after echo $this->Form->submit('submit', array('formnovalidate' => true)); 尝试在echo $ this-> Form-> submit('submit',array('formnovalidate'=> true))之后放置; because the submit method does not include afterwards. 因为之后的Submit方法不包括在内。

You can this $this->Form->end if you don't want to add the form closing tag manually. 如果不想手动添加表单结束标记,则可以使用$ this-> Form-> end。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM