Intergrating Zend Framework 2 and Propel - 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

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.

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

Related

Class '...\Input' not found

I want to implement a search option on my Laravel application, but had this error:Class 'Illuminate\Support\Facades\Input' not found, I have tried to add this row at config/app like this:
'aliases' => [
....
'Input' => Illuminate\Support\Facades\Input::class,
Also at Controller I have added those rows:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
At Route I have added
Route::any('/search',function(){
$image_tmp = $request->image;
$fileName = time() . '.'.$image_tmp->clientExtension();
$q = Input::get ( 'q' );
$book = Book::where('title','LIKE','%'.$q.'%')->get();
if(count($book) > 0)
return view('home')->withDetails($book)->withQuery ( $q );
else return view ('home')->withMessage('No Details found. Try to search again!');
});
But still it doesn't work.
Try this
config/app.php
use Request instead of Input
'aliases' => [
....
'Input' => Illuminate\Support\Facades\Request::class,
And your controller
use Illuminate\Http\Request;
and remove use Illuminate\Support\Facades\Input; top of your code
you have used the class in the controller but your route is never going to one as you are using a closure. so add Input class in your web.php file. at the top of your web.php file add
<?php
use Illuminate\Support\Facades\Input;
if you are using any latest version of laravel, the Input class no longer exists. so use Request class instead
<?php
use Illuminate\Http\Request;
you can use request() global helper too to get request values.
however i would suggest you to not use closure, rather use controller for logical operation.

having a problem about my codes in PagesController

Hi I'm having a problem about my codes in my PagesController.
I'm wondering what is the error about the notification it says undefined variable but it has the same codes in countOrder and countProduct and those two are working just only the notification
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\CustomerOrder;
use App\Product;
use App\Notification;
use DB;
class PagesController extends Controller
{
public function count() {
$countOrder = CustomerOrder::count();
$countProduct = Product::count();
$notification = Notification::count();
return view('/adminIndex',['customer_orders' => $countOrder],['products' => $countProduct],['notifications' => $notification]);
}
}
There may be a few issues here.
Firstly, when passing data to a view, you must use one array (rather than several):
return view('/adminIndex', ['customer_orders' => $countOrder, 'products' => $countProduct, 'notifications' => $notification]);
Secondly, the first argument of the view() helper expects the view file (found in the /resources/views folder). So if the file is adminIndex.blade.php use:
return view('adminIndex', ['customer_orders' => $countOrder, 'products' => $countProduct, 'notifications' => $notification]);
Hope this helps.

PSR-4 autoloader Fatal error: Class not found

I have my project structure like so:
src/
├─ Model/
└─ User.php
My User.php file looks like this:
<?php
namespace Bix\Model;
class User {
And my composer.json autoloader is this:
"autoload": {
"psr-4": {
"Bix\\": "src/"
}
}
Finally my bootstrap.php is this:
use Bix\Model\User;
// PSR-4 Autoloader.
require_once "vendor/autoload.php";
However if I try and create a new User(), I get the error Fatal error: Class 'User' not found in /var/www/public/api/v1/index.php on line 8
Looking at the composer autoload_psr4.php file it looks ok:
// autoload_psr4.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
return array(
'XdgBaseDir\\' => array($vendorDir . '/dnoegel/php-xdg-base-dir/src'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'KeenIO\\' => array($vendorDir . '/keen-io/keen-io/src'),
'Bix\\' => array($baseDir . '/src'),
);
Can anybody point out where I am going wrong with the above?
First of all, Linux (I'm not sure which PC you use) is case-sensitive. In your autoloading, you defined src/bix, while it is src/Bix.
But more importantly, with PSR-4, the specified namespace prefix is not included in the directory structure (to avoid directories containing just one directory). In your case, if you configure "Bix\\": "src/", a class Bix\Model\User should be located in src/Model/User.php.
EDIT: You're misunderstanding PHP namespaces. In PHP, you're not saying "import everything from Bix\Model into the global namespace for this file" with use Bix\Model;. Instead, it means: "Alias Model in this file to Bix\Model".
So you should either do:
require_once "vendor/autoload.php";
use Bix\Model;
$user = new Model\User();
or:
require_once "vendor/autoload.php";
use Bix\Model\User;
$user = new User();

Laravel - I can't call get config helper when I am in another Helper Class

Message:
Class 'Helpers\Config' not found
File:app/classes/Helpers/Helper.php
public static function getDictionary(){
$timezone = Config::get('app.dictionary');
File: config/app.php.
'aliasis => array(
'Helper' => 'Helpers\Helper'
File: app/config/app.php
'dictionary' => array(
'EMAIL' => 'crm#xxxx.com',
'VERSION' => "1.0.0"
)
Is there any namespace or use line that I've missed?
Because you're in a namespace in the Helpers\Helper file, when you refer to Config in that file PHP assumes you mean a class in the Helpers\ namespace. You need to prefix it with a \ to say you mean the 'root' Config class, or use a use statement:
Refer to it directly:
$timezone = \Config::get('app.dictionary');
use it:
use Config;
class Helper
{
public static function getDictionary()
{
$timezone = Config::get('app.dictionary');
// ...
}
}

Laravel 4.1 - calling View Composers class - ReflectionException class does not exist

I keep getting this error when trying to call a View Composer class: Class MyApp/Composers/HeaderComposer does not exist
/app/MyApp/Composers/HeaderComposer.php:
<?php namespace MyApp\Composers;
class HeaderComposer {
public function compose($view) {
$view->with('foo', 'foobar');
}
}
composer.json:
"psr-4": {
"MyApp\\" : "app/MyApp/"
}
routes.php:
View::composer('layouts.default', 'MyApp/Composers/HeaderComposer');
vendor/composer/autoload_psr4.php
<?php
// autoload_psr4.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'MyApp\\' => array($baseDir . '/app/MyApp'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
);
What else could I be missing?
Thanks,
Ham
Change forward slashes in
View::composer('layouts.default', 'MyApp/Composers/HeaderComposer');
to back slashes
View::composer('layouts.default', 'MyApp\Composers\HeaderComposer');
and it will work

Resources