问题
Hello Good People !!
I have a web application (my first of this type) based on Zend Framework 1.11.12 ( upgraded from 1.10.8) using "modular approach" folder structure i mean by that all the modules are under application/modules
. i used Doctrine 1.2.4
i also use library
folder for all the third party libraries including ZF except 2: CKEditor
and PGRFilemanager. pgrfile manager for uploading files to images folder from an admin panel.
here is globally my file structure.
/application
/configs
application.ini
routes.ini
/layouts
/scripts
/partials
*.all_the_partials_files.phtml
*.all_the_layouts.phtml
/modules
all_the_module_folders
Boostrap.php
/logs
/library
/Zend
/Doctrine
/SwiftMailer
/Abra //where all my classes reside
/Model
User.php
Role.php
other_doctrine_entities_class
/public
/javascript
/css
/images
.htaccess // added an htaccess file here
/fonts
`/ckeditor`
a_lot_of_files_including_php_files
other_folders
/plugins
other_folders
`/pgrfilemanager`
/php
auth.php
myconfig.php
other_folders_and_files_including_php
index.php
.htaccess
At the point i was developing this site ,i wasn't using Zend_Acl so the session_start() in /public/ckeditor/plugins/pgrfilemanager/php/auth.php
worked fine for some time since pgrfilemanager came with a default authentication feature. but once i started using Zend_Acl i run into issues like Class __PHP_Incomplete_Class has no unserializer Array
exception when session_start()
is called from the ~~/auth.php
file . I initially thought it was due do the fact i wasn't using Zend_Session
but apparently i was rather due to this fact explained here (correct me if am wrong thanks)
How to use it? Thanks for reading
回答1:
Since i found a workaround about this issue, i thought i would share, maybe i would get better perspective.
The Answer for the Class __PHP_Incomplete_Class has no unserializer Array
is clear now as Session does how which format to unserialize
to meaning php had to know the definition of the object stored in the session.
Based on the file structure i created an auth file say myauth.php
in /public/ckeditor/puglins/pgrfilemanager/userfiles
i will refer to this path is pgr/userdir
$path = realpath("../../../../library");
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require "Zend/Loader/Autoloader.php";
require_once 'Doctrine/Doctrine.php';
spl_autoload_register(array("Doctrine", "autoload"), true);
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace(array("Abra_"));
/*$p seem to be empty throwing error on Zend_Config_Ini but returns the config anyway.I never figured out
*/
$p = realpath("./../../../../application/configs/application.ini");
try {
// $config = parse_ini_file($p, "production");
$config = new Zend_Config_Ini($p, "production");
$conn = Doctrine_Manager::connection($config->doctrine->dsn);
$user = new Abra_Model_User();
$role = new Abra_Model_Role();
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity()|| !in_array($auth->getIdentity()->Role->name, array("superadmin","administrator")) ){
die("Not authenticated");
}
} catch (Exception $ex) {
*/
$p = realpath("./../../../../application/configs/application.ini");
try {
// $config = parse_ini_file($p, "production");
$config = new Zend_Config_Ini($p, "production");
$conn = Doctrine_Manager::connection($config->doctrine->dsn);
$user = new Abra_Model_User();
$role = new Abra_Model_Role();
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity()|| !in_array($auth->getIdentity()->Role->name, array("superadmin","administrator")) ){
die("Not authenticated");
}
} catch (Exception $ex) {
}
}
in pgr/php/folders.php
and pgr/php/files.php
i included the
$path = realpath("../../../../library");
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
at the top. then i included the pgr/userfiles/myauth.php
in pgr/myconfig
as shown below
include_once dirname(__FILE__) . '/userfiles/myauth.php';
I hope this would help someone. thanks
来源:https://stackoverflow.com/questions/12025307/how-to-use-zend-auth-to-authenticate-user-when-uploading-using-ckeditor-plugin-p