1

I want to display images while editing the information of the user. I just bind the form with fetched data and displaying all data with single array i.e form. Also is there any way to get https 500 error? If yes then please show me some code so that I can display the error and check why it is giving HTTPS 500 error.

controller

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,
        );
    }

view file 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 --> 
halfer
  • 19,824
  • 17
  • 99
  • 186
Dev5
  • 67
  • 2
  • 10
  • are you sure basepath is proper I mean path? Please check the img src tag, copy the url of that img tag, and paste it in URL bar and check – Jaymin May 09 '19 at 07:43
  • yes path is correct. but to i want to get each file name in $myimg variable. – Dev5 May 09 '19 at 09:09
  • Can you please print your array and edit it in question? – Jaymin May 09 '19 at 09:26
  • no need for this .. i got the solution. thanks bro for your effort. – Dev5 May 09 '19 at 09:32
  • Closing as "unreproducible" for now. However, if you can add a useful self-answer below, that is much appreciated by future readers. – halfer May 09 '19 at 16:51

0 Answers0