在cake php中,是否可以在当前页面中设置flash消息而不丢失表单值。
这里提交了一个表单,那么我们需要在当前页面设置一条flash消息,并且不丢失表单值。 (不使用ajax/不使用Javascript)
表单已提交,转到 php 并设置 Flash 消息
HTML
<div class="videos form">
<?php echo $this->Form->create('Video');?>
<fieldset>
<legend><?php __('Add Video'); ?></legend>
<?php
echo $this->Form->input('video', array('label' => false, 'div' => false,'type' => 'file','style' =>'height:25px'));
echo $this->Form->input('title');
echo $this->Form->input('name');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
PHP
function add()
{
if (!empty($this->data)) {
$file = $this->data['Video']['video'];
$destination = 'files/videos/';
$max_size = 100 * 1024 * 1024; //100 MB
$allowed_types = array('mp4','flv','WebM','3GPP','avi','wmv','FLV','MP4','AVI','MOV');
$status = $this->FileUpload->uploadFile($file, $destination, $max_size, $allowed_types, $filename);
if ($status == "SUCCESS") {
$userFile = $file['name'];
$extension = pathinfo($userFile, PATHINFO_EXTENSION);
$saveData = array(
'name' => $filename . '.' . $extension,
'path' => $destination
);
return $saveData;
} else {
// If this condition enters flash message is shown, but form values are lost
return $status;
}
}
}
最佳答案
当您在该行设置之后将数据设置到文件时:
$this->Session->setFlash(__('your message', true));
以及您想要在该 View 文件中显示写入的位置:
<?php echo $this->Session->flash(); ?>
关于php - Cake php,在当前页面设置flash消息而不丢失表单内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9494205/