[
'0'=>['someAttribute'=>'somedata', 'someAttribute2'=>'somedata',],
'1'=>['someAttribute'=>'somedata', 'someAttribute2'=>'somedata'],
'N'=>['someAttribute'=>'somedata', 'someAttributeN'=>'somedata'],
]
$('.owl-carousel').owlCarousel({
....
}))
}, 0)
public ngForCallback() {
$(document).ready(function () {
$('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
responsiveClass: true,
autoWidth: false,
navText: ["Предыдущий", "Следующий"],
responsive: {
0: {
items: 1,
nav: true
},
600: {
items: 3,
nav: false
},
1000: {
items: 5,
nav: true,
loop: false,
margin: 20
}
}
});
});
console.log('run');
}
<div class="owl-carousel owl-theme">
<div class="item" *ngFor="let t of test; let last = last">
<span *ngIf="last">{{ngForCallback()}}</span>
<h4>{{t?.name}}</h4>
</div>
</div>
<?php
namespace components;
use common\models\City;
use common\models\Country;
use yii\base\Object;
use yii\web\UrlRuleInterface;
class CountryCityUrlRule extends Object implements UrlRuleInterface
{
public function createUrl($manager, $route, $params)
{
if ($route === 'site/index'){
if ( isset($params['country']) ){
$country = $this->getCountryName($params['country']);
if ( isset($params['city']) ){
$city = $this->getCitiesName($params['country'], $params['city']);
if ($country !== null && $city !== null){
return $country . '/' . $city;
}
}
if ($country !== null) {
return $country;
}
}
}
return false;
}
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) {
if (isset($matches[1])){
$country_id = $this->getCountryId($matches[1]);
if ($country_id === null){
return false;
}
if ( isset($matches[3]) ){
$city_id = $this->getCitiesId($country_id, $matches[3]);
if ($city_id === null){
return false;
}
if ( isset($country_id) && isset($city_id) ){
return ['site/index', ['country' => $country_id, 'city' => $city_id]];
}
}
if ( isset($country_id) ) {
return ['site/index', ['country' => $country_id]];
}
}
}
return false;
}
private function getCountryId($countryName = null)
{
if (isset($countryName)){
$country = Country::getDb()->cache(function ($db) {
return Country::find()->select('id, slug')->asArray()->indexBy('slug')->all();
});
if (array_key_exists($countryName, $country))
return $country[$countryName]['id'];
else
return null;
}
return null;
}
private function getCitiesId($countryId = null, $cityName = null)
{
if (isset($countryId) && isset($cityName)){
$city = City::find()->select('id, slug, country_id')->where(['country_id' => $countryId])->asArray()->indexBy('slug')->all();
//return $city[$cityName]['id'];
if (array_key_exists($cityName, $city))
return $city[$cityName]['id'];
else
return null;
}
return null;
}
private function getCountryName($countryId = null)
{
if (isset($countryId)){
$country = Country::getDb()->cache(function ($db) {
return Country::find()
->select('id, slug')
->asArray()
->indexBy('id')
->all();
});
return $country[$countryId]['slug'];
}
return null;
}
private function getCitiesName($countryId = null, $cityId = null)
{
if ( isset($countryId) && isset($cityId) ){
// $city = City::getDb()->cache(function ($db) {
if (isset($countryId)){
$city = City::find()
->select('id, slug, country_id')
->where(['country_id' => $countryId])
->asArray()
->indexBy('id')
->all();
}
else{
return null;
}
//});
return $city[$cityId]['slug'];
}
return null;
}
}
- скажу больше он без явного указания formName = '' не будет загружать не форму.
Максим Тимофеев, может Вы знаете проще способ как можно за один раз добавить множество позиций?