Zend Framework with Kohana PHP 3 - php

I've put the Zend library folder into classes folder of my app and renamed all files and folders to lowercase ( using Ant Renamer ).
When I call Zend_Feed, instead of loading /classes/zend/feed.php, kohana loads Zend from my servers share\ZendFramework\library\Zend\ (Zend Server), so I get a Cannot redeclare class Zend_Uri_Http error.
ZF version; 1.10
Kohana version: the most recent files available through GitHub
Edit:
https://github.com/kolanos/kohana-zend

Kohana autoloader expects lowercase filenames. You can register both Zend and Kohana autoloaders and it should work fine.
In bootstrap you have:
/**
* Enable the Kohana auto-loader.
*
* #see http://docs.kohanaphp.com/features/autoloading
* #see http://php.net/spl_autoload_register
*/
spl_autoload_register(array('Kohana', 'auto_load'));
Zend autoloader should go before or after that (I don't know if that makes a difference). Found a post how to do it:
http://www.beyondcoding.com/2009/10/29/using-zend-framework-1-8-with-kohana/

its very important that your class name matches the file path in ko3. e.g. your feed class is inside /classes/zend/feed.php so it must be named class Zend_Feed { if you don't like this you can create this file /classes/feed.php and do this class Feed extends Zend_Feed { }

As Pomyk says, try to use both autoloaders: http://www.php.net/manual/en/function.spl-autoload-register.php
Reneming classes is bad practice, because it's very difficult to update and feauture support

Related

Original PHP Session with Zend Framework 2

Zend Framework 2 is not letting me use orginal PHP session. I am using Responsive File Manager Application that is in public folder of zend framework 2. Whenever the dialog of file manager opens, I get following error.
Warning: Class __PHP_Incomplete_Class has no unserializer in E:\xampp\htdocs\MantissaAdmin\public\ResponsiveFilemanager\filemanager\config\config.php on line 2
Where on line 2, the code is
session_start();
How can I make it so that Zend framework 2 do not interfere with the file manager session.
This is not an issue of ZF2. There is a serialized object in your session which php tries to unserialize when session_start is called. But because PHP can't find the class (which is not declared), it uses __PHP_Incomplete_Class instead.
See: PHP: unserialize - Manual
The best way to fix: Register an autoloader to load missing classes. You can dump the class name this way:
ini_set('unserialize_callback_func', '__unserialize_callback_func');
function __unserialize_callback_func($classname)
{
var_dump($classname);
}
session_start();
In order to work with other 3rd party libraries and share sessions across software that may not be ZF2 related; you will need to ensure that you still provide access to the ZF2 autoloader as well as module autoloading. In the shared software make certain before the session starts that you bootstrap the ZF2 autoloader and initialize the ZF2 Application.
$cwd = getcwd();
chdir('/path/to/zf2-application');
require 'init_autoloader.php';
Zend\Mvc\Application::init(require 'config/application.config.php');
chdir($cwd);
session_start();

How to autoload a custom class in Zend Framework 2?

I'm using zend framework2 skeleton, and I'm trying to add my own classes behind vendor folder. The problem is: I don't know how to prepare the classes to be loaded on demand (autoloaded) only when I'll instantiate one of them from any module.
I tried with the solution explained at: How to load a custom library in Zend Framework 2? , but I'm getting the same error:
Fatal error: Class 'myNamespace\myClass' not found in path\IndexController.php on line x
My question is: Where and how should I insert my own classes to be later used from my modules?
Firstly, if they are your own classes and directly related to the modules (i.e not some custom library you have written) then you are better off having them in the actual module, not in the vendor folder.
However, if you are trying to include your own library that you have written I'd suggest you consider storing this elsewhere and adding it as a dependancy via composer.
I don't recommend this but you should be able to get the autoloading working by using the psr0 autoloader built in to composer (assuming your classes follow psr0). Example composer.json config:
{
[...]
"autoload": {
"psr-0": {
"MyNameSpace": "path/to/root/src/directory"
}
}
[...]
}
I know its a bit old but i was facing the same issue so what i did was:
inside vendor folder i created a new folder and gave it the name of Custom. Inside that folder i added my class file (MyClass.php).
inside MyClass.php i added this line (namespace Zend\Custom;).
And inside my Controller at the top
use Zend\Custom\MyClass;
and within a method of that controller
$someVar = new MyClass();
$someVar->someClassMethod();
I hope this helps.

How to use ZF2 ZendPdf in Yii Framework

I want to parse a PDF document in my project, I'm using Yii framework and I'm able to load ZendFramework 1.12, actually I'm using Zend_Lucene and Zend_Mail successfully, but ZendPdf fails to parse the PDF, so I wanted to try with ZF2 (ZendFramework 2), but I'm not able to make it work... I just downloaded the ZF2 library and added the following to my base Controller:
public function __construct($id,$module=null){
Yii::import('application.vendors.ZendFramework.library.*');
Yii::setPathOfAlias('Zend',Yii::getPathOfAlias('application.vendors.ZendFramework.library.Zend'));
parent::__construct($id,$module);
}
So every time I use a Controller this code is executed. Then in the controller I have:
use ZendPdf\PdfDocument;
use Zend\Mail;
class AjaxController extends Controller{...
...
public function actionTestPdf(){
$filepath = realpath('./path/').'/pdftest2.pdf';
$pdf = PdfDocument::load($filepath);
}
When I run the controller: /ajax/TestPdf
I get: Fatal error: Class 'ZendPdf\PdfDocument' not found
What am I doing wrong?
I'd suggest you to install your ZF2 stuff with composer and include the autoloader from composer to get PSR compatible autoloading.
Alternative 1)
You may also try pointing an alias ZendPdf\PdfDocument to the class file location.
Alternative 2)
import the needed classes or directories in your application config.
In this particular case I would recommend NOT using ZendPdf from ZF2, because it is functionally equivalent to Zend_Pdf from ZF1 and so all you're going to do is add unnecessary complexity with classloading, etc, but not solve your underlying problem, as the document will still most likely NOT load using ZendPdf from ZF2.
You should investigate the underlying reason why the document is failing to load in ZF1.

Using ProcessBuilder in a Silex Project

I am wanting to use the Symfony\Component\Process\ProcessBuilder class and can see that it is included as part of the Silex codebase within the vendors folder. I am using the Silex phar file and assume that because I can readily instantiate other Symfony components like Request, Response and so on that it will correctly locate the file to include when I use the full namespace.
$foo = new Symfony\Component\HttpFoundation\Request(); //works fine
However, when I try and create and instance of it using:
$foo = new Symfony\Component\Process\ProcessBuilder(); //class not found
It gives me a class not found error. Does anyone know why this is and how I can use this class from the Silex phar without including the component seperately within my project?
It looks like the Process Symfony component is not included in the compiled Silex phar file.

php zf project: db classes in models directory do not get auto-included

I'm trying to create a Zend Framework project using PHP 5.3.2 and Zend Framework 1.10.3.
i created the source files of the project using the zend framework tool and the db related classes i created with zend-db-model-generator.
example:
in models directory i have the following:
FbUser.php - class Default_Model_FbUser
FbUserMapper.php - class Default_Model_FbUserMapper
DbTable/FbUser.php - class Default_Model_DbTable_FbUser
The models in the models directory should be included automatically when I use them in one of the controllers, but it seems that it doesn't.
what should i configure in order for the db class models will be auto-included when used ?
update
I tried adding the following code to the bootstrap file:
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Default_');
the autoloader still looks for Default/Model/FbUser.php in include path instead of Model/FbUser.php in the zf project.
I did not need to use Zend_Loader_Autoloader at all, although it's a cool component to auto-load classes in your include path.
i need to add to application.ini which is the main config of the application, the following line:
appnamespace = "Default_"
The program understands the application name space and then loads the db model classes properly.

Categories