Example #1
0
 public function addAction()
 {
     if ($this->request->isPost()) {
         $data = $this->request->getPost();
         //load from url
         if ($from_url = $this->request->getPost('from-url')) {
             $data['image'] = $this->request->getPost('image-url');
         } else {
             $file = $this->getRequest()->getFiles('image');
             $data['image'] = 'image';
         }
         $validate = \Sticks\Beans\Stickers::getInputFilter();
         $validate->setData($data);
         $errors = array();
         if ($validate->isValid()) {
             $data = $validate->getValues();
             $img_path = APPLICATION_PATH . '/public/source/sticks/';
             $em = $this->getServiceLocator()->get('em');
             $stick_bean = new Stickers($em);
             $imagebean = new ImageLoader($em, $img_path);
             if ($from_url == 1) {
                 $imagebean->loadFromUrl($data['image']);
             } else {
                 $imagebean->loadFromForm($data['image']);
             }
             if (!count($imagebean->getErrors())) {
                 $data['image'] = $imagebean->getLastSaveImage();
                 $stick_bean->create($data);
             } else {
                 $errors[] = $imagebean->getErrors();
             }
         }
         \Custom\Ajax\Json::response(1, 'Sticked!', $validate->getMessages() + $errors);
     }
 }