TinyMCE、N1ED与CodeIgniter集成问题:无法整合文件管理器
Let's break down the issues in your code and fix them step by step:
1. The Immediate Error: Calling Static Methods Outside Class Methods
In PHP, you can't execute function calls (even static ones) directly in the class body—they need to live inside a class method. Your FlmngrServer::flmngrRequest() call is sitting outside any method, which is why you're getting a syntax error.
2. Understanding :: in PHP
The :: operator is used to access static methods or properties of a class. Since flmngrRequest() is a static method provided by FlmngrServer, using :: is correct—but you just need to put that call inside a controller method that will handle the incoming request (like index()).
3. Proper Path Handling in CodeIgniter
Using relative paths like ../upload/... is risky in CodeIgniter, because the relative path changes depending on where your controller is located. Instead, use CodeIgniter's built-in constants for reliable absolute paths:
FCPATH: Points to your project's root directory (whereindex.phplives)APPPATH: Points to theapplication/folder
Corrected Controller Code
Here's the fixed version of your controller:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); use EdSDK\FlmngrServer\FlmngrServer; class MH_Admin_Filemanager extends MY_Admin_Core { function __construct() { parent::__construct(); } // This method will handle the Flmngr API requests public function index() { // Use absolute paths with FCPATH to avoid relative path issues FlmngrServer::flmngrRequest([ 'dirFiles' => FCPATH . 'upload/filemanager_dir/files', 'dirTmp' => FCPATH . 'upload/filemanager_dir/tmp', 'dirCache' => FCPATH . 'upload/filemanager_dir/cache' ]); } }
Additional Setup Steps
Don't forget these critical details:
- Composer Autoload: Make sure CodeIgniter is loading Composer's autoloader. Open
application/config/config.phpand set:
This ensures the$config['composer_autoload'] = TRUE;EdSDK\FlmngrServernamespace is recognized. - Directory Permissions: Ensure the
upload/filemanager_dir/files,tmp, andcachedirectories have read/write permissions (typically755or777, depending on your server setup). Without this, Flmngr won't be able to save files or process uploads. - Route Configuration: Add a route in
application/config/routes.phpto point Flmngr's frontend requests to this controller:$route['flmngr'] = 'MH_Admin_Filemanager';
How It Works Now
When Flmngr's frontend sends a request to your CodeIgniter app (to the /flmngr route), the index() method of your MH_Admin_Filemanager controller will run, call the static flmngrRequest() method with the correct absolute paths, and handle the file management operations.
内容的提问来源于stack exchange,提问作者spreaderman

