Answers.Body: <pre><code>Craft::$app-&gt;getUrlManager()-&gt;setRouteParams(['calupdateResponse' =&gt; $out]);
  </code></pre>
  
  <p>All <code>Components</code> should be treated as singletons, don't create a new instance of them</p>
  
  <p>Note: you can also do</p>
  
  <pre><code>Craft::$app-&gt;urlManager-&gt;setRouteParams(['calupdateResponse' =&gt; $out]);
  </code></pre>
  
  <p>But it is considered as <a href="https://github.com/craftcms/docs/blob/v3/en/coding-guidelines.md#app-component-getters" rel="nofollow noreferrer">bad practice</a> </p>
  
  <p>Edit: most parts of Craft 3 are working with Craft 2 as well... <code>craft()</code> is just a mapper for <code>Craft::$app</code> </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T06:09:43.043Z
Answers.Text: Thank you, Robin. Works perfectly. And thank you for the programming tips. Does `Components` refer to things accessed by `use Craft;` or `use craft\web\Request`? For instance  
  ```$request = new Request;  
  $timestr  = $request->getParam('time1');```
Answers.UserDisplayName: kr37
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T06:13:33.617Z
Answers.Text: Components are all classes, that `extends Component`. All these have global access from everywhere (Twig & PHP) via `Craft::$app->` and they are usually placed in a `services` folder. Examples are `Craft::$app->entries`, `Craft::$app->sections`, `Craft::$app->fields` and so on. You can see the entire list here https://docs.craftcms.com/api/v3/craft-services-api.html grouped in `craft\services`. Btw.... **don't** do `$request = new Request; ` instead `Craft::$app->getRequest()`
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T15:02:40.147Z
Answers.Text: This is very helpful. Does this guidance apply to plugin classes that `extends Component`?  So in my variable.php, I should replace `$service = new Service;` with `return Service::calendar()` and in the Service, the functions should all be `public static function` ?
Answers.UserDisplayName: kr37
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-24T15:22:15.873Z
Answers.Text: Please read the docs https://github.com/craftcms/docs/blob/v3/en/services.md#what-are-services of course it is the same for Plugin components... just do `MyPlugin::getInstance()->serviceName`.
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-23T15:36:57.003Z
Answers.LastActivityDate: 2018-04-23T15:36:57.003Z
Answers.UserDisplayName: Robin Schambach
Body: <p>What would be the Craft 3 / Yii 2.0 version of<br>
  <code>craft()-&gt;urlManager-&gt;setRouteVariables(array('calupdateResponse' =&gt; $out));</code></p>
  
  <p>This doesn't work (it doesn't complain, either):  </p>
  
  <pre><code>$urlManager = new UrlManager;
  $urlManager-&gt;setRouteParams(['calupdateResponse' =&gt; $out]);
  </code></pre>
  
Tags: <plugin-development><craft3>
Title: Updating plugin to Craft 3: craft()->urlManager->setRouteVariables?
ThreadText: # Updating plugin to Craft 3: craft()->urlManager->setRouteVariables?
  
  (Asked by: username_0 on 2018-04-23)
  
  What would be the Craft 3 / Yii 2.0 version of  
  `craft()->urlManager->setRouteVariables(array('calupdateResponse' => $out));`
  
  This doesn't work (it doesn't complain, either):
  
  ```
  $urlManager = new UrlManager;
  $urlManager->setRouteParams(['calupdateResponse' => $out]);
  
  ```
  
  **Tags:** plugin-development, craft3
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-23. Score: 2 | Accepted answer
  
  ```
  Craft::$app->getUrlManager()->setRouteParams(['calupdateResponse' => $out]);
  
  ```
  
  All `Components` should be treated as singletons, don't create a new instance of them
  
  Note: you can also do
  
  ```
  Craft::$app->urlManager->setRouteParams(['calupdateResponse' => $out]);
  
  ```
  
  But it is considered as [bad practice](https://github.com/craftcms/docs/blob/v3/en/coding-guidelines.md#app-component-getters)
  
  Edit: most parts of Craft 3 are working with Craft 2 as well... `craft()` is just a mapper for `Craft::$app`
  
  > **Comments:**
  > **username_0**: Thank you, username_1. Works perfectly. And thank you for the programming tips. Does `Components` refer to things accessed by `use Craft;` or `use craft\web\Request`? For instance   ```$request = new Request;   $timestr  = $request->getParam('time1');```  
  > **username_1**: Components are all classes, that `extends Component`. All these have global access from everywhere (Twig & PHP) via `Craft::$app->` and they are usually placed in a `services` folder. Examples are `Craft::$app->entries`, `Craft::$app->sections`, `Craft::$app->fields` and so on. You can see the entire list here https://docs.craftcms.com/api/v3/craft-services-api.html grouped in `craft\services`. Btw.... **don't** do `$request = new Request; ` instead `Craft::$app->getRequest()`  
  > **username_0**: This is very helpful. Does this guidance apply to plugin classes that `extends Component`?  So in my variable.php, I should replace `$service = new Service;` with `return Service::calendar()` and in the Service, the functions should all be `public static function` ?  
  > **username_1**: Please read the docs https://github.com/craftcms/docs/blob/v3/en/services.md#what-are-services of course it is the same for Plugin components... just do `MyPlugin::getInstance()->serviceName`.  
  
  ---
  
  