我开发了Angular和Yii2 REST服务.在跨域有问题.下面添加我的angular&Yii2 REST代码.
AngularJs:(像' http://organization1.example.com ', ' http://organization2.example.com ',....)
$http.defaults.useXDomain = true;
$http.defaults.withCredentials = true;
$http.defaults.headers.common['Authorization'] = 'Bearer ' + MYTOKEN
Run Code Online (Sandbox Code Playgroud)
我来自Angular Controller的请求:
apiURL = 'http://api.example.com';
$http.get(apiURL + '/roles')
.success(function (roles) { })
.error(function () { });
Run Code Online (Sandbox Code Playgroud)
Yii2 .htaccess :( REST网址如' http://api.example.com ')
Header always set Access-Control-Allow-Origin: "*"
Header always set Access-Control-Allow-Credentials: true
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "Authorization,X-Requested-With, content-type"
Run Code Online (Sandbox Code Playgroud)
Yii2我的行为:
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['corsFilter'] = [
'class' …
Run Code Online (Sandbox Code Playgroud) 我想创建包含开始,结束时间和休息时间的时隙.
public function getServiceScheduleSlots($duration,$break, $stTime,$enTime)
{
$start = new DateTime($stTime);
$end = new DateTime($enTime);
$interval = new DateInterval("PT" . $duration. "M");
$period = new DatePeriod($start, $duration, $end);
foreach ($period as $dt) {
$periods[] = $dt->format('H:iA');
}
return $periods;
}
Run Code Online (Sandbox Code Playgroud)
例如,
我的服务开始时间为上午10:00,结束时间中午12:00.
条件: 每个服务时间30分钟和15分钟休息.
上面的方法返回如,
预期结果为,
我想在每个时段开始时添加休息时间.
提前致谢.