2015-10-15 65 views
0

我试图运行一个Symfony任务,但是当我尝试实例化一个类时,我得到一个致命错误。Symfony 1.4任务无法访问类

类位于

  • 应用
    • MyApp的
      • LIB

我的代码如下

protected function execute($arguments = array(), $options = array()) 
    { 
    $this->reloadAutoload(); 

    // initialize the database connection 
    $databaseManager = new sfDatabaseManager($this->configuration); 
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); 

    // Get file from dir 
    if(!in_array($arguments['filename'] . $this->fileExt, scandir($this->path))) { 
     $this->logSection('Import CSV', 'File doesn\'t exist.', null, 'ERROR'); 
     return; 
    } 

    $path = $this->path . '/' . $arguments['filename'] . $this->fileExt; 

    if(class_exists('CsvReader')) { 
     $csvReader = new CsvReader($path); 
    } else { 
     $this->logSection('Import CSV', 'Class doesn\'t exist.', null, 'ERROR'); 
     return; 
    } 

    // add your code here 
    $this->logSection('Import CSV', 'All content imported.'); 
    } 

如果有什么我失踪然后让我知道,我会修改我的问题。

谢谢。

回答

0

有可能会阻止您在您的应用程序调用类有两件事情:

  1. 需要刷新缓存与php symfony cc
  2. 你的Symfony自动加载机无法找到你的班级,因为文件名不.class.php

来源结束:Documentation

+0

凯文您好,感谢您的回复。我完成了这两个,它仍然无法实例化。我刚刚采用旧的skool方式,只是使用require_once完成工作。 –