---
title: "Class (specified by alias blog) Blog\\Controller\\BlogController could not be located i"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/189567-class-specified-by-alias-blog-blog-controller-blogcontroller-could-not-be-located-i"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Dykarn"
published: "2012-04-06T19:13:19.000Z"
updated: "2012-04-06T19:13:19.000Z"
replies: 0
views: 307
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/189567-class-specified-by-alias-blog-blog-controller-blogcontroller-could-not-be-located-i"
---

# Class (specified by alias blog) Blog\Controller\BlogController could not be located i

## #1 — Dykarn, 2012-04-06T19:13Z

Hej Alla,
Forsoker lara mig ZF2 genom att modifiera Skeleton application till en blog blog. 

Men nu har jag fatt ett felmedelande som sager
"Class (specified by alias blog) Blog\\Controller\\BlogController could not be located in provided definitions." 

min  BlogController.php ser ar

\<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\>

MIn BlogTable.php ser ut som

\<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\>

Koden ar baserad paZF2 beta 3

Permalänk: https://www.webforum.nu/p/189567

---

Tråden på webben: https://www.webforum.nu/amne/php/189567-class-specified-by-alias-blog-blog-controller-blogcontroller-could-not-be-located-i
