1

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.

Craft::import('plugins.aifeed.resources.Date_Formatting');

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

<?php
namespace Craft;

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

Craft::import('plugins.aifeed.resources.Date_Formatting');

}
}

in Resources folder: DateFormatting.php

<?php
namespace Craft;

class DateFormatting
{
$strDate_A=$strSampleDate;
echo '$strDate_A test...'.$strDate_A.'<br>';
}
2

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.

Edit:

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.

Edit2:

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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