我想在编辑用户信息时显示图像。我只是将表单与获取的数据绑定在一起,并使用单个数组即表单显示所有数据。还有什么办法可以得到https 500错误?如果是,那么请向我显示一些代码,以便我可以显示该错误并检查为什么它给出了HTTPS 500错误。
控制器
public function editAction() {
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('business', array(
'action' => 'add'
));
}
try {
$business = $this->getBusinessTable()->getBusiness($id);
} catch (\Exception $ex) {
return $this->redirect()->toRoute('business', array(
'action' => 'index'
));
}
$form = new BusinessForm();
$form->bind($business); /// values to the form
$form->get('submit')->setAttribute('value', 'Update business info');
$request = $this->getRequest();
if ($request->isPost()) {
// $form->setData($request->getPost());
$post = array_merge_recursive(
$request->getPost()->toArray(),
$request->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$this->getBusinessTable()->saveBusiness($business);
// Redirect to list of Student
return $this->redirect()->toRoute('business');
}
}
return array(
'id' => $id,
'form' => $form,
);
}
查看文件edit.phtml
<?php
$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url(NULL, array('controller' => 'TaskForce', 'action' => 'add')));
$form->setAttribute('method', 'post');
//echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
?>
<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">Add Bsuiness</div>
<div class="panel-body">
<?php echo $this->form()->openTag($form); ?>
<fieldset>
<div class="col-md-6">
<div class="form-group">
<?php echo $this->formElement($form->get('fname')); ?>
</div>
<div class="form-group">
<?php echo $this->formElement($form->get('lname')); ?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<?php echo $this->formElement($form->get('phone')); ?>
</div>
<div class="form-group">
<?php echo $this->formElement($form->get('email')); ?>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<?php echo $this->formElement($form->get('address')); ?>
</div>
<div class="form-group">
<?php echo $this->formElement($form->get('company')); ?>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<?php echo $this->formElement($form->get('images')); ?>
</div>
<?php print_r($form->get('images')); ?>
<?php $img_ar=explode(',', $form->images); ?>
<ul>
<?php foreach ($img_ar as $myimg) { ?>
<li>
<img src="<?php echo $this->basePath(); ?>/images/<?php echo $myimg; ?>" style="width: 60px;height: 60px;"></li>
<?php } ?>
</div>
<div class="col-md-12">
<?php echo $this->formElement($form->get('submit')); ?>
</div>
</fieldset>
<?php echo $this->form()->closeTag();
?>
</div>
</div>
</div><!-- /.col-->
</div><!-- /.row -->