简体   繁体   English

控制器没有在phalcon php中显示消息

[英]controller not displaying a message in phalcon php

I'm trying to make a simple example in Phalcon PHP framework, so i have a view which contain two fields name and email and a submit button. 我试图在Phalcon PHP框架中做一个简单的例子,所以我有一个视图,其中包含两个字段名称和电子邮件以及一个提交按钮。 When i click in this button a function of a controller is called to store the name and the email in the DB. 当我单击此按钮时,将调用控制器的功能以将名称和电子邮件存储在DB中。 This action goes well the problem is I'm trying to display a message after the action ends but i still have the view that contain the form (name, email). 这个动作很顺利,问题是我试图在动作结束后显示一条消息,但我仍然有包含表单(名称,电子邮件)的视图。 Here's my code. 这是我的代码。

My checkout controller. 我的结账控制器。

 <?php class CheckoutController extends \\Phalcon\\Mvc\\Controller { public function indexAction() { } public function registerAction() { $email = new Emails(); //Stocker l'email et vérifier les erreurs $success = $email->save($this->request->getPost(), array('name', 'email')); if ($success) { echo "Thanks for shopping with us!"; } else { echo "Sorry:"; foreach ($user->getMessages() as $message) { echo $message->getMessage(), "<br/>"; } } } } 

The view 风景

 <!DOCTYPE html> <html> <head> <title>Yuzu Test</title> </head> <body> <?php use Phalcon\\Tag; ?> <h2>Checkout</h2> <?php echo Tag::form("checkout/register"); ?> <td> <tr> <label for="name">Name: </label> <?php echo Tag::textField("name") ?> </tr> </td> <td> <tr> <label for="name">E-Mail: </label> <?php echo Tag::textField("email") ?> </tr> </td> <td> <tr> <?php echo Tag::submitButton("Checkout") ?> </tr> </td> </form> </body> </html> 

You can use Flash Messages , so you don't have to break the application flow. 您可以使用Flash消息 ,因此您不必破坏应用程序流。 Regards 问候

echo() during controller code won't (shouldn't) work unless you turn off your views, because its buffered and cleared after dispatching. 控制器代码中的echo()不会(不应该)工作,除非你关闭你的视图,因为它在调度后被缓冲和清除。

If you want to be sure it's happening this way, just add die() at the end of registerAction() method. 如果你想确保它以这种方式发生,只需在registerAction()方法的末尾添加die()

If you create separate view for registerAction() , you can use there variables you declare with $this->view->message = ... or $this->view->setVar('message', ...) in controller method. 如果为registerAction()创建单独的视图,则可以在控制器中使用$this->view->message = ...$this->view->setVar('message', ...)声明的变量方法。 Than, in view file you can reuse them by <?php echo $this->view->message; ?> 在视图文件中,您可以通过<?php echo $this->view->message; ?>重用它们<?php echo $this->view->message; ?> <?php echo $this->view->message; ?> or <? echo $message; ?> <?php echo $this->view->message; ?><? echo $message; ?> <? echo $message; ?> <? echo $message; ?> . <? echo $message; ?>

I think you have to write following line in the end of your controller function registerAction 我想你必须在控制器函数registerAction的末尾写下面一行

$this->view->disable(); $这 - >查看 - >禁用();

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

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