How To Dispatch A Controller Into A Url?

By dispatch I mean to make the controller act like a default URL. Here is the scenario:

I have a controller storage that has actions: download, view, preview

I need to make a request to /storage/preview/id/345 and /storage/view/id/345




<a href="/storage/view/id/345">

   <img src="/storage/preview/id/345">

</a>



Where the logic should look like the following:




	public function actionView($id) {

		$model = FileObject::model()->find($id);

		if($model->isPicture()) {

			$data = $model->readData();

			header('Content-type: '.$model->mime_type);

			header('Content-Disposition: inline; filename="'.$model->name.'"');

			header('Content-Length: '.$model->size);

			echo $data;

		} else {

			$this->dispatch(['download','id'=>$id]);	

		}

	}

	

	public function actionPreview($id) {

		$model = FileObject::model()->find($id);

		if($model->isPicture()) {

			$this->dispatch(['view','id'=>$id]);

		} else {

			$url = Yii::app()->assetManager->publish(Yii::app()->theme->basePath.'/images/no-preview.png')

			$this->dispatch($url);

		}

	}




The dispatch function isn’t a redirect, all it does is to “make” the action act like the given url. Is that possible? Through extensions or core?

  • Gasim