سؤال

I have a script with cURL to initiate other script that import products and categories in prestashop.

This is the script which start with cURL:

define('_PS_ADMIN_DIR_', getcwd());
include_once(_PS_ADMIN_DIR_.'/../config/config.inc.php');
include_once(_PS_ADMIN_DIR_.'/../config/defines.inc.php');
include_once(_PS_ADMIN_DIR_.'/functions.php');
include_once dirname(__FILE__).'/../controllers/admin/AdminImportController.php';

if (!isset($_GET['entity'])) die(); 

$import = New AdminImportController(); 
switch ($_GET['entity']) { 
case 0: 
    loadCategoriesPost(); 
    $import->categoryImport(); 
    break;

  case 1:
    loadProductsPost();
    $import->productImport();
    break;

}

My problem is that the seconds script generate an error from "include_once dirname(FILE).'/../controllers/admin/AdminImportController.php';":

PHP Fatal error: Cannot redeclare class AdminImportControllerCore in...

I have tried to use include_once, DIR, also I looked for in that included files a line with "new AdminImportController();" but I don't found nothing.

Thanks!

هل كانت مفيدة؟

المحلول

Look inside the AdminImportController.php file. My guess is that it is also including the file that defines the AdminImportControllerCore class, and that it is not using the include_once verity of the include functions.

That would mean that your main page is defining the class through the include_once call, and then when it includes the AdminImportController class, the include there kicks in and tries to re-define the core class, with the results you described.

I suggest you look into PHP's autoloader feature. It'll save you all the headaches associated with manually including files like that. It also tends to promote good file and class naming practices.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top