i have form , controller zf 2. can upload file , other data, can not write @value of path@ of file database table value of field. displays value array in field of table database ! how change controller or somewhere else , save value of file path not array in field of table?
restaurantcontroller.php
$form = new restaurantform(); $form->get('submit')->setvalue('Добавить ресторан'); $request = $this->getrequest(); if ($request->ispost()) { $restaurants = new restaurant(); $form->setinputfilter($restaurants->getinputfilter()); $data= array_merge_recursive( $this->getrequest()->getpost()->toarray(), $this->getrequest()->getfiles()->toarray() ); $form->setdata($data); if ($form->isvalid()){ //array_map('unlink', glob('./public/img/restaurants*'));{ $restaurants->exchangearray($form->getdata()); $this->getrestaurantstable()->saverestaurant($restaurants); // form valid, save form! // redirect list of albums return $this->redirect()->toroute('zfcadmin/restaurants'); } } //else return $this->redirect()->toroute('zfcadmin'); return array('form' => $form); }
restaurantform.php
// file input $file = new element\file('restaurant_thumbnail'); $file->setlabel('Загрузите главный рисунок ресторана') ->setattribute('id', 'image-file'); $this->add($file);
restaurant.php
#version2 // $inputfilter = new inputfilter(); // file input //https://github.com/cgmartin/zf2fileuploadexamples/blob/master/src/zf2fileuploadexamples/form/singleupload.php $file = new fileinput('restaurant_thumbnail'); $file->setrequired(true); $file->getfilterchain()->attachbyname( 'filerenameupload', array( 'target' => './public/img/restaurants/*', 'overwrite' => true, 'use_upload_name' => true, ) ); $inputfilter->add($file);
Comments
Post a Comment