public function submit() { /*$this->load->library('unit_test'); echo $this->unit->run($this->input->post('number_of_contacts'), 4); return;*/ if ($this->_submit_validate() === FALSE) { $this->add(); return; } $tags = explode(',', $this->input->post('tags')); $tagsArray = array(); foreach ($tags as $tag) { $tag1 = $this->em->getRepository('models\\Tag')->findOneBy(array('name' => trim($tag))); if (!($tag1)){ $tag1 = new models\Tag; $tag1->setName(trim($tag)); $this->em->persist($tag1); $this->em->flush(); } $tagsArray[] = $tag1; } $user = models\Current_User::user(); $post = NULL; if ($this->input->post('edit') == 0) { $post = new models\Post; } else { $post = $this->em->find('models\Post', $this->input->post('post_id')); } $post->setUser($user); $post->setTitle($this->input->post('title')); $post->setContent($this->input->post('content')); $post->setTags($tagsArray); $this->em->persist($post); $this->em->flush(); $this->db->cache_delete('posts','index'); $this->index(); }
public function addPosts() { $user1 = $this->em->find('models\User','1'); $post = new models\Post; $post->setUser($user1); $post->setTitle("First Post"); $post->setContent("Lorem ipsum first post bla bla bla"); $tag1 = new models\Tag; $tag1->setName('iseng'); $tag2 = new models\Tag; $tag2->setName('first'); $tag3 = new models\Tag; $tag3->setName('ppion'); $this->em->persist($tag1); $this->em->persist($tag2); $this->em->persist($tag3); $post->setTags(array($tag1, $tag2, $tag3)); $this->em->persist($post); $this->em->flush(); $data['message'] = 'done'; $this->load->view('home', $data); }