本文整理汇总了PHP中app\components\Helper::getDateIntervalYesterdayInDashOrSlashFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::getDateIntervalYesterdayInDashOrSlashFormat方法的具体用法?PHP Helper::getDateIntervalYesterdayInDashOrSlashFormat怎么用?PHP Helper::getDateIntervalYesterdayInDashOrSlashFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\components\Helper
的用法示例。
在下文中一共展示了Helper::getDateIntervalYesterdayInDashOrSlashFormat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
public function up()
{
for ($i = 0; $i < 45; $i++) {
$data = Helper::getDateIntervalYesterdayInDashOrSlashFormat(new \DateTime(), $i, 'slash');
$url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=' . $data;
$xml_contents = file_get_contents($url);
if ($xml_contents === false) {
throw new \ErrorException('Error loading ' . $url);
}
$xml = new \SimpleXMLElement($xml_contents);
$date = $xml->attributes()->Date;
foreach ($xml as $node) {
$current_curr = new \app\models\CurrHistory();
if (\app\models\Currencies::findOne(['valute_id' => $node->attributes()->ID])) {
$current_curr->currency_id = \app\models\Currencies::findOne(['valute_id' => $node->attributes()->ID]);
} else {
$new_currency = new \app\models\Currencies();
$new_currency->name = $node->Name;
$new_currency->valute_id = $node->attributes()->ID;
$new_currency->char_code = $node->CharCode;
$new_currency->num_code = $node->NumCode;
$new_currency->save();
$current_curr->currency_id = $new_currency->id;
}
$current_curr->date = $date;
$current_curr->nominal = $node->Nominal;
$current_curr->value = $node->Value;
$current_curr->save();
}
}
}
示例2: actionCurrencyTest
public function actionCurrencyTest()
{
//for($i=0; $i<45; $i++) {
echo $i = 0;
$data_slash = Helper::getDateIntervalYesterdayInDashOrSlashFormat(new \DateTime(), $i, 'slash');
$data_dash = Helper::getDateIntervalYesterdayInDashOrSlashFormat(new \DateTime(), $i, 'dash');
$url = 'http://www.cbr.ru/scripts/XML_daily.asp?date_req=' . $data_slash;
$xml_contents = file_get_contents($url);
if ($xml_contents === false) {
throw new \ErrorException('Error loading ' . $url);
}
$xml = new \SimpleXMLElement($xml_contents);
//$date = $xml->attributes()->Date;
foreach ($xml as $node) {
$current_curr = new CurrHistory();
//var_dump($node->attributes()->ID);
if (Currencies::find()->where('valute_id like "%' . $node->attributes()->ID . '%"')->one()) {
// var_dump(Currencies::find()->where('valute_id like "%'.$node->attributes()->ID.'%"')->one());
$current_curr->currency_id = Currencies::find()->where('valute_id like "%' . $node->attributes()->ID . '%"')->one()->id;
} else {
$new_currency = new Currencies();
$new_currency->name = TranslateHelper::translit($node->Name);
$new_currency->valute_id = $node->attributes()->ID;
$new_currency->char_code = $node->CharCode;
$new_currency->num_code = $node->NumCode;
$new_currency->save(false);
$current_curr->currency_id = $new_currency->id;
//var_dump($new_currency); exit;
}
$current_curr->date = $data_dash;
$current_curr->nominal = $node->Nominal;
$current_curr->value = str_replace(',', '.', $node->Value);
//замена запятой на точку позволят использовать
//формат с плавоющей точкой
$current_curr->save(false);
//echo $current_curr->value; exit;
}
// }
}