我試圖爲cakephp應用程序添加布局,但現在我的驗證消息不再顯示。在驗證對博客條目的評論時,不會顯示這些假設位於頂部的驗證郵件。在cakephp應用程序中缺少驗證消息
0
A
回答
0
如果你改變佈局意味着你錯過了之前的
其他可能的地方加入
<?php
if ($this->Session->check('Message.flash')){
echo $this->Session->flash();
}
?>
是在電流控制器。
$this->Session->setFlash('...');
第一個代碼負責顯示信息,而第二個是負責設置消息:
,如果你有這樣的代碼搜索。
但肯定的代碼將幫助更多:)
0
這裏是comments_controller.php我的附加功能
function add(){
debug($this->data);
//if the user submitted a comment post
if (!empty($this->data)){
//display the 'add view'
$this->Comment->create();
if ($this->MathCaptcha->validates($this->data['Comment']['security_code'])) {
if ($this->Comment->save($this->data)){
$this->Session->setFlash(__('The Comment has been added.', true));
$this->redirect('/posts/index/'.$this->data['Comment']['post_id']);
}
//failed validation
else{
debug($this->data);
$this->Session->setFlash(__('Comment could not be saved. Please try again.', true));
}
}
else {
$this->Session->setFlash(__('Please enter the correct answer to the math question.', true));
$this->redirect('/posts/index/'.$this->data['Comment']['post_id']);
}
這是我entry.ctp在我的文章和評論駐留:
<div id="article">
<h2><?php echo $entry[0]['Post']['title']; ?></h2>
<p class="date"><em>Modified:</em> <?php $date = new DateTime($entry[0]['Post']['modified']);
echo $date->format('Y-m-d');?></p>
<p class="date"><em>Author:</em> <?php echo $entry[0]['User']['username']; ?></p>
<p class="intro"><?php echo $entry[0]['Post']['content']; ?></p>
<h2>Comments:</h2>
<div id="comments_success"></div>
<!-- show the comment -->
<?php
echo $form->create('Comment', array('action' => 'add'));
echo $form->input('name', array('class' => 'validate[required] text-input'));
echo $form->input('email', array('class' => 'validate[required,custom[email]] text-input'));
echo $form->input('text', array('id' => 'commenttext', 'type' => 'textarea', 'label' => 'Comment:', 'rows' => '10', 'class' => 'validate[required] text-input'));
//captcha
echo $form->input('security_code', array('label' => 'Please Enter the Sum of ' . $mathCaptcha));
echo $form->input('Comment.post_id', array('value' => $entry[0]['Post']['id'] , 'type' => 'hidden'));
echo $form->end('Submit');
?>
<!-- comments -->
<ol>
<?php
foreach ($entry[0]['Comment'] as $comment) :
?>
<li>
<h3><?php echo $comment['name']; ?></h3>
<p class="date"><em>Date:</em> <?php echo $comment['created']; ?></p>
<p class="text"> <?php echo $comment['text']; ?></p>
</li>
<?php
endforeach;
?>
</ol>
</div>
這是我的posts_controller中的索引函數
function index($entry_id = null) {
if (isset($entry_id)){
$entry = $this->Post->findAllById($entry_id);
$comments = $this->Post->Comment->getCommentsFromPostID($entry_id);
$this->set('entry' , $entry);
$this->set('mathCaptcha', $this->MathCaptcha->generateEquation());
$this->render('entry');
}
else{
$posts = $this->Post->find('all');
$this->set(compact('posts'));
}
}
0
我知道這是舊的,但UST確保你有下面的代碼在您的應用程序/視圖/佈局/ default.thtml中顯眼的地方(或任何你爲這個應用程序佈局)
<?php echo $this->Session->flash(); ?>
它如果沒有要顯示的消息,將不會回顯,但如果有消息,則會相應地輸出。
相關問題
- 1. 使用DropDownListFor缺少驗證消息
- 2. CakePHP驗證錯誤消息
- 3. 驗證應用程序塊 - 自定義驗證程序 - 消息模板
- 4. cakephp自定義驗證規則消息
- 5. CakePHP的驗證消息的位置
- 6. 在Android Studio中缺少調試信息的Android應用程序
- 7. 如何禁用ClickOnce消息:「驗證應用程序要求」
- 8. zend驗證程序過早消息
- 9. 刪除jQuery驗證程序消息
- 10. 在預覽API中缺少驗證碼
- 11. Freemarker缺少彈簧消息
- 12. TestProbe缺少akka消息
- 13. 驗證消息
- 14. 缺少列模式驗證
- 15. 驗證缺少的數據
- 16. Cakephp在兩個應用程序之間共享驗證
- 17. Spring和ActiveMQ在響應消息中缺少關聯ID
- 18. 驗證信息cakephp錯誤?
- 19. 驗證應用程序並將應用程序提交給App Store的Xcode警告:缺少所需密鑰:CFBundleShortVersionString
- 20. 用於adobe air應用程序的cakephp用戶身份驗證
- 21. 在rhomobile應用程序中驗證
- 22. 缺少信息提交應用程序時
- 23. rails驗證消息
- 24. jquery驗證消息
- 25. HTML5 - 驗證消息
- 26. JSF驗證消息
- 27. HTML5驗證消息?
- 28. 與驗證消息
- 29. Html.EditorFor驗證消息
- 30. Facebook - 默認應用程序可見性和信息中缺少的信息
代碼請問?這樣,我們可能知道什麼是錯的 – 2010-07-22 14:30:32
正如君說的,你應該發佈相關的代碼。特別是驗證數組(或設置錯誤消息的任何地方),以及模板(ctp)中應顯示啓動器消息的部分。 – webbiedave 2010-07-22 14:35:04