Eric Smith
Eric Smith

Reputation: 33

Intergrating Zend Framework 2 and Propel

I've searched far and wide on how to intergrate propel and Zend Framework 2 however I haven't been able to come up with a solution yet.

Here is what I have so far.

Installed ZF2 Skeleton Directory Inserted Sample Album Table Data from ZF site

My Folder Structure looks like this

--Vendor
----Propel
------album
--------autoload_classmap.php
--------models
----------map
----------om
----------Album.php
----------AlbumPeer.php
----------AlbumQuery.php
------config
--------module.config.php
------Module.php
------autoload_classmap.php

The album/autoload_classmap.php looks like this

//vendor/Propel/album/autoload_classmap.php
<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
    'AlbumTableMap'  => __DIR__ . '/models/map/AlbumTableMap.php',
    'BaseAlbumPeer'  => __DIR__ . '/models/om/BaseAlbumPeer.php',
    'BaseAlbumQuery' => __DIR__ . '/models/om/BaseAlbumQuery.php',
    'BaseAlbum'      => __DIR__ . '/models/om/BaseAlbum.php',
    'Album'          => __DIR__ . '/models/Album.php',
    'AlbumPeer'      => __DIR__ . '/models/AlbumPeer.php',
    'AlbumQuery'     => __DIR__ . '/models/AlbumQuery.php',
);

Here is the module.config.php

//vendor/Propel/config/module.config.php
<?php
return array();

Here is the Propel/autoload_classmap.php

//vendor/Propel/autoload_classmap.php

<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
    'Propel'                                              => __DIR__ . '/runtime/lib/Propel.php',
);

and finally the Model.php file

    //vendor/Propel/Module.php
<?php

namespace Propel;

class Module
{

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
                __DIR__ . '/album/autoload_classmap.php'
            )
        );
    }

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

For the sake of simplicity in this example I put the following code into my Controller.

//module/Application/src/Application/Controller/IndexController.php
namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        $q = new \Propel\Album();
        $q->setArtist('The Who');
        $q->setTitle('Tommy');
        $q->save();

        return new ViewModel();
    }
}

The error I get is

 Class 'Propel\\Album' not found

The sources I used to get to this point were

https://groups.google.com/forum/?fromgroups=#!searchin/propel-users/zend/propel-users/lsHs-jjxp68/LDrQjzik6gAJ https://docs.google.com/viewer?a=v&pid=forums&srcid=MDU2NDIxODQyNDc0MDMyNjQ3NzUBMDY3ODcxMTYzMzg0MDA4OTU0MzgBeFpDZUM1WTZqMThKATQBAXYy Adding Vendor Specific Module To Zend Framework 2.0

Upvotes: 3

Views: 2847

Answers (2)

Boban Acimovic
Boban Acimovic

Reputation: 21

If you didn't set namespace in your XML schema, your classes should be accessible in the root namespace, so as \Album for example. If you want to have some other namespace, you shoud define it in database tag of your XML schema. And you should not use Propel namespace anyway as it is reserved for Propel itself. Your generated classes should be long to the namespace of your project.

Upvotes: 2

DrBeza
DrBeza

Reputation: 2251

\Propel\Album is not being found because the class map specifies Album as the class name.

I'm guessing if you added the line: namespace Propel; to each of those Propel related files the classmap generator would put the correct class names. Of course then you would need update an class names in the code that are affected.

Upvotes: 0

Related Questions