CakePHP电子邮件在主页上的注册表单

时间:2017-05-09 14:12:02

标签: php cakephp model-view-controller

我需要带有电子邮件输入的注册表单才能在网站上的任何地方工作。 我有一个带有add()的EmailsController,当我在添加页面时会添加一封电子邮件。

如何在保留功能并向用户提供反馈的同时,将Emails / Add.ctp的布局注入我的主页以及我喜欢的任何位置?

<div>
<?= $this->Element('upone_scriptimports'); ?>
<?= $this->Form->create() ?>
<?php echo $this->Form->control('email'); ?>
<?= $this->Form->button(__('Submit'), ['class'=>'btn btn-default text-right right']) ?>
<?= $this->Form->end() ?>
</div>

1 个答案:

答案 0 :(得分:0)

您将使用元素,请参阅CookBook

将代码放在此处:src/Template/Element/Emails/add.ctp,您使用的元素如下echo $this->element('Emails/add');

  

还要在表单中添加一个action属性,指定控制器   以及处理数据的行动。

<?= $this->Form->create(null, [
    'url' => ['controller' => 'Articles', 'action' => 'publish']
]); ?>
<?= $this->Form->control('email'); ?>
<?= $this->Form->button(__('Submit'), [
    'class' => 'btn btn-default text-right right'
]); ?>
<?= $this->Form->end(); ?>

参见 Setting a URL for the Form