integrating phpthumb in zend framework

2019-09-20 07:13发布

Is there a easy way to integrate phpthumb in zend framework ? Please help me with sample code if possible, thanks

3条回答
走好不送
2楼-- · 2019-09-20 07:33

application/Bootstrap.php

protected function _initAutoload()
{
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->registerNamespace('PhpThumb_');
    return $autoloader;
} 

application/configs/application.ini

[production]
includePaths.library = APPLICATION_PATH "/../library"

put files in

library
--PhpThumb
查看更多
疯言疯语
3楼-- · 2019-09-20 07:49

My answer is based on this answer by David Weinraub as it may not be clear to you how to translate that answer to your situation. I suppose you wouldn't have posted this question otherwise.

I am assuming you are using the Zend Framework recommended directory structure.

Under your library directory create a phpthumb directory and copy all the files from the zip archive into it.

Add the following line to application.ini

autoloadernamespaces[] = "phpthumb_"

Create your autoloader, mine is in App/Loader/Autoloader/PHPThumb.php and looks like this:-

class App_Loader_Autoloader_PHPThumb implements Zend_Loader_Autoloader_Interface
{
    public function autoload($class)
    {
        if ('phpthumb' != $class){
            return false;
        }
        require_once 'phpthumb/phpthumb.class.php';
        return $class;
    }
}

Initialise your autoloader in your bootstrap:-

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 
{
    protected function _initAutoloading() {
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->pushAutoloader(new App_Loader_Autoloader_PHPThumb());
    }
}

Once that is done you can use php thumb thus:-

$phpthumb = new phpthumb();
var_dump($phpthumb);

I have tested this only so far as to instantiate an instance of phpthumb, I haven't tested it's functionality. Also, you may be able to delete many of the files in the phpthumb directory as it looks to me as if many of them are demo files.

查看更多
仙女界的扛把子
4楼-- · 2019-09-20 07:53

Create a directory name custom inside your 'library' folder . Inside this 'Custom' directory put PHPThumb library as it is . Basically we are exploiting the fact library directory is part of include_path . So now wheresoever you want to use it just simply do

require_once'Custom/PHPThumb/ThumbLib.inc.php'
查看更多
登录 后发表回答