Beginner: problems with the tutorial

For programming and general questions on Zend Framework

Beginner: problems with the tutorial

Postby vero5554 on Wed Jan 25, 2017 3:28 pm

I am a beginner.
Start by reading the initial tutorial of ZF2 which I followed step by step.
When I try to see the result I get this error:
Code: Select all
Fatal error: Uncaught Error: Class 'Album\Model\Album' not found in C:\xampp\htdocs\miapp2\module\Album\Module.php:52 Stack trace: #0 [internal function]: Album\Module->Album\{closure}(Object(Zend\ServiceManager\ServiceManager), 'albumtablegatew...', 'AlbumTableGatew...') #1 C:\xampp\htdocs\miapp2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(939): call_user_func(Object(Closure), Object(Zend\ServiceManager\ServiceManager), 'albumtablegatew...', 'AlbumTableGatew...') #2 C:\xampp\htdocs\miapp2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(1099): Zend\ServiceManager\ServiceManager->createServiceViaCallback(Object(Closure), 'albumtablegatew...', 'AlbumTableGatew...') #3 C:\xampp\htdocs\miapp2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(638): Zend\ServiceManager\ServiceManager->createFromFactory('albumtablegatew...', 'AlbumTableGatew...') #4 C:\xampp\htdocs\miapp2\vendor\zendframework\zendframework\library\Zend\Service in C:\xampp\htdocs\miapp2\module\Album\Module.php on line 52

Since I do not understand much what I'm doing, I can not see where the problem is.
Attach Modulo.php for review.
Thank you and sorry for my ignorance on this subject ....
Code: Select all
<?php

namespace Album;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Album\Model\Album;
use Album\Model\AlbumTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

class Module implements AutoloaderProviderInterface
{

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

     // Add this method:
     public function getServiceConfig()
     {
         return array(
             'factories' => array(
                 'Album\Model\AlbumTable' =>  function($sm) {
                     $tableGateway = $sm->get('AlbumTableGateway');
                     $table = new AlbumTable($tableGateway);
                     return $table;
                 },
                 'AlbumTableGateway' => function ($sm) {
                     $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                     $resultSetPrototype = new ResultSet();
                     $resultSetPrototype->setArrayObjectPrototype(new Album());
                     return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
                 },
             ),
         );
     }

}
vero5554
 
Posts: 1
Joined: Wed Jan 25, 2017 3:16 pm

Re: Beginner: problems with the tutorial

Postby mehm8471 on Sun Feb 05, 2017 8:13 pm

ResultSet is trying to use the Album entity class and can't find it.
Which is defined as Album\Model\Album and supposed to be saved as entity class in module/Album\src\Model\Album.php defined like below:

Code: Select all
/* module/Album/src/Model/Album.php */
namespace Album\Model;
class Album
{
// ...
}


Do you have this file with the correct namespace and class name?

Suat
mehm8471
 
Posts: 20
Joined: Sat Jun 21, 2014 11:39 pm

Re: Beginner: problems with the tutorial

Postby john5394 on Sat Feb 11, 2017 12:35 am

How to begin the tutorial? I would like to check the content of it.
john5394
 
Posts: 2
Joined: Sat Feb 11, 2017 12:28 am
Location: UK

Re: Beginner: problems with the tutorial

Postby mehm8471 on Sat Feb 11, 2017 12:44 am

Zend Framework Tutorials: Great starting point.
Zend Framework Tutorials

Note: I also started a blog and posting my own tutorial if you are interested:
Online Book Catalog Application Tutorial

Suat
mehm8471
 
Posts: 20
Joined: Sat Jun 21, 2014 11:39 pm

Re: Beginner: problems with the tutorial

Postby amarbhanu on Sat Apr 15, 2017 7:56 pm

My first module Index is working but when i created Album Module then not working show error, any idea please.


viewtopic.php?f=69&t=132428&p=264868#p264868
An error occurred
An error occurred during execution; please try again later.
Additional information:
Error
File:
D:\xampp\htdocs\mockadmin\module\Album\Module.php:45
Message:
Class 'Album\Controller\AlbumController' not found
Stack trace:
#0 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(747): Album\Module->Album\{closure}(Object(Zend\ServiceManager\ServiceManager), 'Album\\Controlle...', NULL)
#1 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-servicemanager\src\ServiceManager.php(195): Zend\ServiceManager\ServiceManager->doCreate('Album\\Controlle...')
#2 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-servicemanager\src\AbstractPluginManager.php(143): Zend\ServiceManager\ServiceManager->get('Album\\Controlle...')
#3 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-mvc\src\DispatchListener.php(95): Zend\ServiceManager\AbstractPluginManager->get('Album\\Controlle...')
#4 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-eventmanager\src\EventManager.php(271): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#5 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-eventmanager\src\EventManager.php(151): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#6 D:\xampp\htdocs\mockadmin\vendor\zendframework\zend-mvc\src\Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#7 D:\xampp\htdocs\mockadmin\public\index.php(48): Zend\Mvc\Application->run()
#8 D:\xampp\htdocs\mockadmin\index.php(2): include('D:\\xampp\\htdocs...')
#9 {main}
amarbhanu
 
Posts: 15
Joined: Mon May 11, 2009 2:45 pm

Re: Beginner: problems with the tutorial

Postby mehm8471 on Sun Apr 16, 2017 12:25 am

Check the namespace of the class: should be Album\Controller
Check the class name: should be AlbumController
Check module.config.php for the controller definition.

Follow the steps in the tutorial to find out a possible typo you might have.

Suat
mehm8471
 
Posts: 20
Joined: Sat Jun 21, 2014 11:39 pm


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 1 guest

cron