I currently am developing a plugin to gather XML restful data. At one point in the file, I need to reference another PHP file, which will process various data.

As a test, the code in the included file should return output, as well (see code below).

I've tried to utilize the following code, but it doesn't work. There is no error message, but again there is no data output.


I've been looking here, but it wasn't clear to me how or if the 'included' file could be utilized. Thanks for any leads.

Here is my code:

in Variables folder: AiFeedVariable.php

namespace Craft;

class AiFeedVariable
        public function XmlVariable($optional = null)
$strSampleDate = '2015-12-23';



in Resources folder: DateFormatting.php

namespace Craft;

class DateFormatting
echo '$strDate_A test...'.$strDate_A.'<br>';

1 Answer 1


You can simply load the file normally via php require once

require_once( __DIR__ . '/resources/DateFormatting.php');
$dataFormatter = new DateFormatting();

From your plugins init function or where ever you would like to call it.


I hope your DateFormatting is not like you posted it because it has no functions. Btw Craft::import() has the advantage that you can import entire folders and it loads the class only to Yiis classmap which means that it is only loaded when you need it and not until then. If you want to use the file for sure, require once is the better way since Craft/Yii does the same in the very end.


Never mind, Yii uses include and not require_once, sry for the wrong info here. However... today the difference is not that big issue. Comparison include vs require_once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.