|
Hi all,
Apologies if i am posting in the wrong forum. Trying to learn zf2 by modifying the Skeleton application to a blog. However it looks like i am stuck. i currently get a error that says "Class (specified by alias blog) Blog\Controller\BlogController could not be located in provided definitions." my BlogController.php looks like this <code> <?php namespace Blog\Controller; use Zend\Mvc\Controller\ActionController, Blog\Model\BlogTable, Blog\Form\BlogForm, Zend\View\Model\ViewModel; class BlogController extends ActionController { protected $blogTable; public function indexAction() { return new ViewModel(array( 'blogs' => $this->blogTable->fetchAll(), )); } public function viewActions() { } public function addAction() { $form = new BlogForm(); $form->submit->setLabel('Add'); $request = $this->getRequest(); if ($request->isPost()) { $formData = $request->post()->toArray(); if ($form->isValid($formData)) { $title = $form->getValue('title'); $alternative_title = $form->getValue('alternative_title'); $description = $form->getValue('description'); $category_id = $form->getValue('category_id'); $published_state = $form->getValue('published_state'); $this->blogTable->addBlog($title, $alternative_title, $description, $category_id, $published_state); // Redirect to list of blogs return $this->redirect()->toRoute('default', array( 'controller' => 'blog', 'action' => 'index', )); } } return array('form' => $form); } public function editAction() { } public function deleteAction() { } public function setBlogTable(BlogTable $blogTable) { $this->blogTable = $blogTable; return $this; } } </code> My BlogTable.php look like this <code> <?php namespace Blog\Model; use Zend\Db\TableGateway\TableGateway, Zend\Db\Adapter\Adapter, Zend\Db\ResultSet\ResultSet; class BlogTable extends TableGateway { public function __construct(Adapter $adapter = null, $databaseSchema = null, ResultSet $selectResultPrototype = null) { return parent::__construct('blog', $adapter, $databaseSchema, $selectResultPrototype); } public function fetchAll() { $resultSet = $this->select(); return $resultSet; } public function getBlog($id) { $id = (int) $id; $rowset = $this->select(array('id' => $id)); $row = $rowset->current(); if (!$row) { throw new \Exception("Could not find row $id"); } return $row; } public function addBlog($title,$alternative_title,$description,$category_id,$published_state) { $data = array( 'title' => $title, 'alternative_title' => $alternative_title, 'description' => $description, 'category_id' => $category_id, 'published_state' => $published_state, ); $this->insert($data); } public function updateBlog($id, $title, $alternative_title, $description, $category_id, $published_state) { $data = array( 'title' => $title, 'alternative_title' => $alternative_title, 'description' => $description, 'category_id' => $category_id, 'published_state' => $published_state ); $this->update($data, array('id' => $id)); } public function deleteBlog($id) { $this->delete(array('id' => $id)); } } </code> The code is based on ZF2 beta 3, all help welcome Thanks in advacne |
|
Did you provide autoloading for your "Blog" module?
Marco Pivetta http://twitter.com/Ocramius http://marco-pivetta.com On 5 April 2012 23:55, fwahlqvist <[hidden email]> wrote: > Hi all, > Apologies if i am posting in the wrong forum. > Trying to learn zf2 by modifying the Skeleton application to a blog. > > However it looks like i am stuck. i currently get a error that says > "Class (specified by alias blog) Blog\Controller\BlogController could not > be > located in provided definitions." > > my BlogController.php looks like this > > <code> > <?php > namespace Blog\Controller; > > use Zend\Mvc\Controller\ActionController, > Blog\Model\BlogTable, > Blog\Form\BlogForm, > Zend\View\Model\ViewModel; > > > class BlogController extends ActionController > { > > protected $blogTable; > > public function indexAction() > { > return new ViewModel(array( > 'blogs' => $this->blogTable->fetchAll(), > )); > } > > public function viewActions() > { > > } > > public function addAction() > { > $form = new BlogForm(); > $form->submit->setLabel('Add'); > > $request = $this->getRequest(); > if ($request->isPost()) { > $formData = $request->post()->toArray(); > if ($form->isValid($formData)) { > $title = $form->getValue('title'); > $alternative_title = $form->getValue('alternative_title'); > $description = $form->getValue('description'); > $category_id = $form->getValue('category_id'); > $published_state = $form->getValue('published_state'); > $this->blogTable->addBlog($title, $alternative_title, > $description, $category_id, $published_state); > // Redirect to list of blogs > return $this->redirect()->toRoute('default', array( > 'controller' => 'blog', > 'action' => 'index', > )); > } > } > return array('form' => $form); > } > > public function editAction() > { > > } > > public function deleteAction() > { > > } > > public function setBlogTable(BlogTable $blogTable) > { > $this->blogTable = $blogTable; > return $this; > } > > } > </code> > > > > My BlogTable.php look like this > > <code> > <?php > namespace Blog\Model; > > use Zend\Db\TableGateway\TableGateway, > Zend\Db\Adapter\Adapter, > Zend\Db\ResultSet\ResultSet; > > class BlogTable extends TableGateway > { > public function __construct(Adapter $adapter = null, $databaseSchema = > null, > ResultSet $selectResultPrototype = null) > { > return parent::__construct('blog', $adapter, $databaseSchema, > $selectResultPrototype); > } > > public function fetchAll() > { > $resultSet = $this->select(); > return $resultSet; > } > > public function getBlog($id) > { > $id = (int) $id; > $rowset = $this->select(array('id' => $id)); > $row = $rowset->current(); > if (!$row) { > throw new \Exception("Could not find row $id"); > } > return $row; > } > > > public function > > addBlog($title,$alternative_title,$description,$category_id,$published_state) > { > $data = array( > 'title' => $title, > 'alternative_title' => $alternative_title, > 'description' => $description, > 'category_id' => $category_id, > 'published_state' => $published_state, > ); > $this->insert($data); > } > > > public function updateBlog($id, $title, $alternative_title, > $description, $category_id, $published_state) > { > $data = array( > 'title' => $title, > 'alternative_title' => $alternative_title, > 'description' => $description, > 'category_id' => $category_id, > 'published_state' => $published_state > ); > $this->update($data, array('id' => $id)); > } > > > public function deleteBlog($id) > { > $this->delete(array('id' => $id)); > } > > } > </code> > > The code is based on ZF2 beta 3, all help welcome > > Thanks in advacne > > > -- > View this message in context: > http://zend-framework-community.634137.n4.nabble.com/Class-specified-by-alias-blog-Blog-Controller-BlogController-could-not-be-located-in-provided-defini-tp4536180p4536180.html > Sent from the Zend Framework mailing list archive at Nabble.com. > > -- > List: [hidden email] > Info: http://framework.zend.com/archives > Unsubscribe: [hidden email] > > > |
| Powered by Nabble | Edit this page |
