public function executeEdit() { $post = \Posts::retrieveById($this->request()->get('id')); $taxonomy = $this->request()->get('taxonomy'); if (!$post) { Session::getInstance()->setFlash('post_error', t('Post not found')); $this->redirect($this->createUrl('post/default', array('taxonomy' => $taxonomy))); } if (null == $taxonomy) { $taxonomy = $post->getTaxonomy(); } $error = array(); if ($this->request()->isPostRequest()) { if ($this->_save($post, $error)) { Session::getInstance()->setFlash('post_message', t($post->getTitle() . ' was saved')); $this->redirect($this->createUrl('post/default', array('taxonomy' => $taxonomy))); } } $images = \PostPeer::getPostImg($post->getId()); $files = \PostPeer::getPostAttachments($post->getId()); //Hydrate $jsData = $post->toArray(); $jsData['images'] = []; foreach ($images as $img) { $t = $img->toArray(); $t['thumb_url'] = $img->getThumbs(96, 96); $t['url'] = $img->getUrl(); $jsData['images'][] = $t; } $jsData['files'] = []; foreach ($files as $f) { $jsData['files'] = $f->toArray(); } $this->document()->addJsVar('post', $jsData); //JS URL $this->document()->addJsVar('img_upload_url', $this->createUrl('post_img/upload')); $this->document()->addJsVar('img_remove_url', $this->createUrl('post_img/remove')); $this->document()->addJsVar('img_set_main_url', $this->createUrl('post_img/make_star')); $this->document()->addJsVar('img_update_url', $this->createUrl('post_img/update')); $this->setView('Post/form'); $this->view()->assign(array('post' => $post, 'taxonomy' => $taxonomy, 'error' => $error, 'page_title' => t('Edit ' . $post->getTitle()))); return $this->renderComponent(); }