我是Extbase的新手。我要访问两个XML文件。一个是abc.dll?type = xml,我从中选择ID,然后使用此ID来获取其他XML文件的值(xyzzy.dll?type = xml并将所有数据保存到db。我想创建一个任务,然后从命令行运行它。
下面是我的代码:
$ GLOBALS ['TYPO3_CONF_VARS'] ['SC_OPTIONS'] ['extbase'] ['commandControllers'] [] ='TYPO3 \ Example \ Command \ XMLFetcherCommandController';
XMLFetcherCommandController:
namespace TYPO3\Example\Command;
class XMLFetcherCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController{
/**
* xmlload
*
* @return void
*/
public function findCommand(){
$path="http://abc.dll?type=room&content=xml";
$readXML=file_get_contents($path);
$xml = simplexml_load_string($readXML, "SimpleXMLElement",LIBXML_NOCDATA); $objectManager=\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$classesRepository = $objectManager->get('TYPO3\\Example\\Domain\\Repository\\ClassesRepository');
$json=json_encode($xml);
$xmlArray=json_decode($json,true);
$serialized_array = serialize($xmlArray);
$unserialized_array = unserialize($serialized_array);
$rooms = $unserialized_array['Rooms']['Room'];
foreach($rooms as $room){
$fetchXML= \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\Example\\Domain\\Model\\Classes');
$fetchXML->setRoomKey($room['Key']);
$fetchXML->setRoomID($room['ID']);
$classesRepository->add($fetchXML);
$newpaths[]='http:/xyz.dll?content=xml&type=room&id='.$room['ID'];
foreach($newpaths as $newpath){
$readLessons=file_get_contents($newpath);
$xmlLessons= simplexml_load_string($readLessons, "SimpleXMLElement",LIBXML_NOCDATA);
$objectManager=\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$classesRepository = $objectManager->get('Example\\Example\\Domain\\Repository\\ClassesRepository');
$json=json_encode($xml);
$xmlArray=json_decode($json,true);
$serialized_array = serialize($xmlArray);
$unserialized_array = unserialize($serialized_array);
$Lessons = $unserialized_array['Lesson'];
foreach ($Lessons as $Lesson) {
$fetchXMLNew= \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Example\\Example\\Domain\\Model\\Classes');
$date=date('Ymd',strtotime($Lesson['Date']));
$start=date('Hi',strtotime($Lesson['Start']));
$finish=date('Hi',strtotime($Lesson['Finish']));
$startdatetime=date('YmdHi',strtotime("$date$start"));
$finishdatetime=date('YmdHi',strtotime("$date$finish"));
$fetchXMLNew->setStartdatetime($startdatetime);
$fetchXMLNew->setEnddatetime($finishdatetime);
$classesRepository->add($fetchXML);
}
}
}
$classesRepository->persistAll();
}
}
}
?>
When I run- php cli_dispatch.phpsh extbase help - from cmd, I could not see my command controller which means it is not registered properly. Could you suggest if this is the right way to do it? At First, I created a Service and tried to call it, but since there was a lot of data it was taking a lot of time.
答案 0 :(得分:0)
也许它不起作用,因为您的类无法使用自动加载器加载?
如果一个班级不可用,则不会注册。 (@参见CommandManager-> getAvailableCommands!class_exists($ className))。
我认为您需要转义反斜杠(=>双斜杠)
if shuffle:
dataset = dataset.shuffle(buffer_size='total training instances size')
如果这不起作用,您还可以检查类的命名空间。为什么它以“ TYPO3”开头?
如果这还是行不通,您可以尝试在AdditionalConfiguration.php中加载用require_once硬编码的类,以找出错误所在