Installing Uploader Plugin for CakePHP 2.x

人走茶凉 提交于 2019-12-11 06:38:48

问题


So I'm new at this whole CakePHP thing, but I'm looking to get the Uploader plugin installed. I'm stuck at the first installation step, after download/placing the files in the correct place: http://milesj.me/code/cakephp/uploader. I see this is the code I need to add somewhere:

// CakePHP 2
CakePlugin::load('Uploader');
App::import('Vendor', 'Uploader.Uploader');
$this->Uploader = new Uploader();

But I don't know where to put it! I'm using the basic "Blog tutorial", but I changed the name from "Posts" to "Media". Where would I put this code to get the plugin included? I'm not sure on the rest of the steps either, so if anyone could help me with that in terms of the default "Blog tutorial" setup, that'd be awesome. Thanks!

EDIT: I have the CakePlugin part working. I'm just unsure about the App:import line. I keep trying to add it inside my MediaController class, but it's just throwing errors. Where would this line go?

EDIT: App:import line is working, now I just need the new Uploader() part


回答1:


I havn't used this specific plugin, but I have used one similar (MeioUpload).

The CakePlugin::load('Uploader') goes in your bootstrap configuration file (app/config/bootstrap.php)

App::import and the creation are likely to be handled within your "Media" controller.

For example. My Cake App uses App::uses('Sanitize', 'Utility'); in its PostController.

EDIT:

I assume it would be something like this.

<?php
    App::import('Vendor', 'Uploader.Uploader');
    class MediaController extends AppController {
        $this->Uploader = new Uploader();
        /* The rest of the controller */
    }

But I could be wrong. The explanation for that plugin is weird.



来源:https://stackoverflow.com/questions/10134827/installing-uploader-plugin-for-cakephp-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!