Is it possible to load a specific asset i.e css or js via controller method?

I have two controllers.In controller one which fetches a view i want to use some css file and also some js file.I want to do the same for controller two but the css and js for the two files are not the same at all.

Is it possible to indicate that in a controller so as the css file that is loaded is the one i want and not any other?.

I have made this


public function actionHi(){

	$baseUrl = Yii::$app->baseUrl; 

	$cs = Yii::$app->getClientScript();

	$cs->registerScriptFile($baseUrl.'/js/yourscript.js');

	$cs->registerCssFile($baseUrl.'/css/yourcss.css');

	$message = 'hello';

	return $this->render('not_sober',['message' => $message]);

	}

which gives me the error

I think that you are using in wrong way controllers and views.

Can you explain your goal or your problem?


	public function actionHi()

	{

		$url = \Yii::getAlias('@web'). '/asdasd.asd';

		$this->view->registerCssFile($url);

		$this->view->registerJsFile($url);


....



Try




yii\helpers\Url::base()



instead Yii::$app->baseUrl

I wanted to load my assets using the controller but i will just stick to loading as usual.