Пример #1
0
 /**
  * get alias by name
  *
  * @param type $name the name
  *
  * @return type
  */
 private function getAliasByName($name = '')
 {
     $alias = '';
     if (!empty($name)) {
         //Clean string
         $name = Utilities::cleanString($name);
         $alias = strtolower(str_replace(' ', '-', $name));
     }
     return $alias;
 }
Пример #2
0
 /**
  * update action
  *
  * @param \Symfony\Component\HttpFoundation\Request $request request
  * @param type                                      $id      id
  *
  * @return type
  *
  * @throws type
  */
 public function updateAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $entity = $this->getDoctrine()->getRepository("CMSAdminBundle:Media")->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Media entity.');
     }
     $deleteForm = $this->createDeleteForm($id);
     $editForm = $this->createForm(new MediaType(), $entity);
     $editForm->bind($request);
     if ($editForm->isValid()) {
         if (is_object($entity)) {
             if (!empty($entity->file)) {
                 $newName = Utilities::renameForFile($entity->file->getClientOriginalName());
                 //get upload path
                 $uploadPath = $this->container->getParameter('upload');
                 $webDir = $this->container->get('kernel')->getRootDir() . '/../web';
                 $uploadDir = $webDir . $uploadPath;
                 //upload file
                 $entity->file->move($uploadDir, $newName);
                 //set new name
                 $entity->setName($newName);
             }
             //saving data
             $em->persist($entity);
             $em->flush();
         }
         return $this->redirect($this->generateUrl('admin_media_edit', array('id' => $id)));
     }
     return $this->render('CMSAdminBundle:Media:edit.html.twig', array('entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }