controllers/GalleryController.php
public function actionIndex($format= false,$arraymap= false,$term = false,$tag = false)
    {
        $searchModel = new GallerySearch();        
        $req = Yii::$app->request->queryParams;
        if ($term) { 
			$req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;			
        }        
        if ($tag) { 
			$req[basename(str_replace("\\","/",get_class($searchModel)))]["tag"] = $tag;			
        }        
        $req[basename(str_replace("\\","/",get_class($searchModel)))]["status"] = 1;
        $dataProvider = $searchModel->search($req);				

        if ($format == 'json')
        {
			$model = [];
			foreach ($dataProvider->getModels() as $d)
			{
				$obj = $d->attributes;
				if ($arraymap)
				{
					$map = explode(",",$arraymap);
					if (count($map) == 1)
					{
						$obj = (isset($d[$arraymap])?$d[$arraymap]:null);
					}
					else
					{
						$obj = [];					
						foreach ($map as $a)
						{
							$k = explode(":",$a);						
							$v = (count($k) > 1?$k[1]:$k[0]);
							$obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null));
						}
					}
				}
				
				if ($term)
				{
					if (!in_array($obj,$model))
					{
						array_push($model,$obj);
					}
				}
				else
				{	
					array_push($model,$obj);
				}
			}			
			return \yii\helpers\Json::encode($model);	
		}
		else
		{					
			
		
			$tags=[];
			$items=[];
			$n = 0;
			$model = [];
			foreach ($dataProvider->getModels() as $data)
			{
				if (!empty($data->tags) && (!isset($req['GallerySearch']['tag'])))
				{					
					foreach(explode(",",$data->tags) as $tag)
					{
						if (!isset($tags[strtolower($tag)]))
						{
							$n += 1;
							$tags[strtolower($tag)]=array('id'=>$n,'data'=>array(),'url'=>$data->url,'type'=>-1,'tags'=>$tag,'title'=>ucwords($tag),'description'=>$data->description);
							array_push($tags[strtolower($tag)]['data'],$data->image);
						}
						else
						{
							if (count($tags[strtolower($tag)]['data']) < 4)
							{
								array_push($tags[strtolower($tag)]['data'],$data->image);
							}
						}
					}
				}
				else
				{
					if (!isset($items[$data->id]))
					{
						$n += 1;
						$items[$data->id]=array('id'=>$n,'data'=>array(0=>$data->image),'url'=>$data->url,'type'=>$data->type,'tags'=>$data->tags,'title'=>$data->title,'description'=>$data->description);
					}							
				}
				
			}
			$albums = array_merge($tags,$items);
		
		
			return $this->render('index', [
				'searchModel' => $searchModel,
				'dataProvider' => $dataProvider,
				'albums' => $albums,
			]);
		}	
    }
public function actionIndex($format= false,$arraymap= false,$term = false,$tag = false)
    {
        $searchModel = new GallerySearch();        
        $req = Yii::$app->request->queryParams;
        if ($term) { 
			$req[basename(str_replace("\\","/",get_class($searchModel)))]["term"] = $term;			
        }        
        if ($tag) { 
			$req[basename(str_replace("\\","/",get_class($searchModel)))]["tag"] = $tag;			
        }        
        $req[basename(str_replace("\\","/",get_class($searchModel)))]["status"] = 1;
        $dataProvider = $searchModel->search($req);				

        if ($format == 'json')
        {
			$model = [];
			foreach ($dataProvider->getModels() as $d)
			{
				$obj = $d->attributes;
				if ($arraymap)
				{
					$map = explode(",",$arraymap);
					if (count($map) == 1)
					{
						$obj = (isset($d[$arraymap])?$d[$arraymap]:null);
					}
					else
					{
						$obj = [];					
						foreach ($map as $a)
						{
							$k = explode(":",$a);						
							$v = (count($k) > 1?$k[1]:$k[0]);
							$obj[$k[0]] = ($v == "Obj"?json_encode($d->attributes):(isset($d->$v)?$d->$v:null));
						}
					}
				}
				
				if ($term)
				{
					if (!in_array($obj,$model))
					{
						array_push($model,$obj);
					}
				}
				else
				{	
					array_push($model,$obj);
				}
			}			
			return \yii\helpers\Json::encode($model);	
		}
		else
		{					
			
		
			$tags=[];
			$items=[];
			$n = 0;
			$model = [];
			foreach ($dataProvider->getModels() as $data)
			{
				if (!empty($data->tags) && (!isset($req['GallerySearch']['tag'])))
				{					
					foreach(explode(",",$data->tags) as $tag)
					{
						if (!isset($tags[strtolower($tag)]))
						{
							$n += 1;
							$tags[strtolower($tag)]=array('id'=>$n,'data'=>array(),'url'=>$data->url,'type'=>-1,'tags'=>$tag,'title'=>ucwords($tag),'description'=>$data->description);
							array_push($tags[strtolower($tag)]['data'],$data->image);
						}
						else
						{
							if (count($tags[strtolower($tag)]['data']) < 4)
							{
								array_push($tags[strtolower($tag)]['data'],$data->image);
							}
						}
					}
				}
				else
				{
					if (!isset($items[$data->id]))
					{
						$n += 1;
						$items[$data->id]=array('id'=>$n,'data'=>array(0=>$data->image),'url'=>$data->url,'type'=>$data->type,'tags'=>$data->tags,'title'=>$data->title,'description'=>$data->description);
					}							
				}
				
			}
			$albums = array_merge($tags,$items);
		
		
			return $this->render('index', [
				'searchModel' => $searchModel,
				'dataProvider' => $dataProvider,
				'albums' => $albums,
			]);
		}	
    }
Lists all Gallery models.
@params string $format, array $arraymap, string $term
@return mixed