From [[https://www.tutorialspoint.com/yii/yii_using_actions.htm]]\\

First we create our own controller and view file, look here [[yii2usingcontrollers]]\\

To create an **action** in a controller class, you should define a public method whose name starts with the word **action**. The return data of an action represents the response to be sent to the end user.\\

A //Hello World// action for the //ExampleController.php//\\
<code php>
 public function actionHelloWorld()
 {
  return 'Hello World!';
 }
</code>
Going to ''http://localhost/web/index.php?r=example/hello-world'' will return a page with ''Hello World''\\
Action IDs are usually verbs, such as create, update, delete and so on. This is because actions are often designed to perform a particular change of a resource.\\

There are two types of actions: **inline** and **standalone**\\
Inline actions are defined in the controller class. The names of the actions are derived from //action ID//s this way −\\

  * Turn the first letter in all words of the action ID into uppercase
  * Remove hyphens
  * Add the action prefix

Examples −\\

//index// becomes //actionIndex//\\
//hello-world// becomes //actionHelloWorld//\\

If you plan to reuse the same action in different places, you should define it as a standalone action.\\

Create a Standalone Action Class\\
To create a standalone action class, you should extend //yii\base\Action// or a child class, and implement a //run()// method.

**Step 1** − Create a //components// folder inside your project root. Inside that folder create a file called ''GreetingAction.php'' with the following code
<code php>
<?php

namespace app\components;
use yii\base\Action;

class GreetingAction extends Action
{
 public function run()
 {
  return "Greeting";
 }
}
?>
</code>

We have just created a reusable action. To use it in our //ExampleController//, we should declare our action in the action map by overriding the actions() method\\

**Step 2** − Modify the //ExampleController.php// file this way.
<code php>
 public function actions()
 {
  return ['greeting'=>'app\components\GreetingAction', ];
 }
</code>

The //actions()// method returns an array whose values are class names and keys are action IDs.\\

**Step 3** − Go to http://localhost:8080/index.php?r=example/greeting. You will see an output with "Greeting"\\

**Step 4** − You can also use actions to redirect users to other URLs. Add the following action to the ExampleController.php
<code php>
 public function actionOpenGoogle()
 {
  return $this->redirect('https://google.com.my');
 }
</code>
So http://localhost:8080/index.php?r=example/open-google will redirected the page to http://google.com.my\\

The action methods can take parameters, called //action parameters//. Their values are retrieved from $_GET using the parameter name as the key.\\

**Step 5** − Add the following action to the example controller
<code php>
 public function actionTestParams($first, $second)
 {
  return "First = $first, Second = $second";
 }
</code>
**Step 6** − http://localhost:8080/index.php?r=example/testparams&first=hello&second=world will return a page with ''hello world''\\

Each controller has a default action. When a route contains the //controller ID// only, it means that the default action is requested. By default, the action is index. You can easily override this property in the controller.\\
Putting this into the example controller
<code php>
public $defaultAction = "hello-world";
</code>
and calling http://localhost:8080/index.php?r=example will show "Hello World"\\