<commit_before>At a basic level, Controllers are the code that is executed when you visit a page within XF. Controllers are generally responsible for handling user input and passing that user input to the appropriate place which, generally, would be to perform some sort of database action (Model) or load visual content (View).
 
When a user clicks a link, the requested URL is routed to a specific controller and controller action. See [Routing basics](/routing-basics). For example, in XF if you click a URL like `index.php?conversations/add` you will be routed to the `XF\Pub\Controller\Conversation` controller and to the `add` action.
 
If you look at this class in the file system (see <a href="/general-concepts/#autoloader">Autoloader</a> for a description of how classes and file paths map to each other) you will notice that there are a number of methods named with a prefix of `action`. All of these methods indicate a specific controller action. So, to see the code involved when viewing the conversations/add page mentioned above, look in this file for `public function actionAdd()`.

XF controllers are responsible for returning a reply object which generally consist of one of the following types:

## View reply
 
This is one of the most common replies you will deal with during XF development. A controller which returns a view reply will usually require up to three arguments to be passed in. A view class (more on that below), a template name, and an array of `$viewParams` which is the data that should be available to the template.

Here's a typical example of a controller action which returns a View reply:

```php
public function actionExample()
{
    $hello = 'Hello';
    $world = 'world!';
    
    $viewParams = [
        'hello' => $hello,
        'world' => $world
    ];
    return $this->view('Demo:Example', 'demo_example', $viewParams);
}
```

The first argument is the short class name for a specific View class. This class may or may not exist (often it won't need to exist, we'll cover view classes more later) but it should have a roughly unique name for the controller and action. As with other [Short class names](/general-concepts/#short-class-names), the particular short class name above will resolve to `Demo\Pub\View\Example`. Again, `Pub` is inferred automatically from the controller type.

The second argument is the template name. In this case, we're looking for a template named `demo_example`.

The third argument is an array of template parameters/variables that should be available to the view. This array should generally be `key => value` pairs. The above example is passing two template params to the template. The `key` part of the array indicates the name of the variable available within the template. The `value` part of the array indicates the value.

So, if we had the following contents in the `demo_example` template:

```html
{$hello} {$world}
```

The template would output the following:

```plain
Hello world!
```

## Redirect reply

This reply is returned when you wish to redirect a user to a different URL after they have completed some sort of action.

A common use case here is after a user has submitted data through a form you may wish to redirect them to a different page, for example returning a user to a list of items. A redirect reply takes a 

Here's an example of a typical controller action that performs a redirect:
<commit_msg>Remove an incomplete (and redundant) sentence<commit_after>At a basic level, Controllers are the code that is executed when you visit a page within XF. Controllers are generally responsible for handling user input and passing that user input to the appropriate place which, generally, would be to perform some sort of database action (Model) or load visual content (View).
 
When a user clicks a link, the requested URL is routed to a specific controller and controller action. See [Routing basics](/routing-basics). For example, in XF if you click a URL like `index.php?conversations/add` you will be routed to the `XF\Pub\Controller\Conversation` controller and to the `add` action.
 
If you look at this class in the file system (see <a href="/general-concepts/#autoloader">Autoloader</a> for a description of how classes and file paths map to each other) you will notice that there are a number of methods named with a prefix of `action`. All of these methods indicate a specific controller action. So, to see the code involved when viewing the conversations/add page mentioned above, look in this file for `public function actionAdd()`.

XF controllers are responsible for returning a reply object which generally consist of one of the following types:

## View reply
 
This is one of the most common replies you will deal with during XF development. A controller which returns a view reply will usually require up to three arguments to be passed in. A view class (more on that below), a template name, and an array of `$viewParams` which is the data that should be available to the template.

Here's a typical example of a controller action which returns a View reply:

```php
public function actionExample()
{
    $hello = 'Hello';
    $world = 'world!';
    
    $viewParams = [
        'hello' => $hello,
        'world' => $world
    ];
    return $this->view('Demo:Example', 'demo_example', $viewParams);
}
```

The first argument is the short class name for a specific View class. This class may or may not exist (often it won't need to exist, we'll cover view classes more later) but it should have a roughly unique name for the controller and action. As with other [Short class names](/general-concepts/#short-class-names), the particular short class name above will resolve to `Demo\Pub\View\Example`. Again, `Pub` is inferred automatically from the controller type.

The second argument is the template name. In this case, we're looking for a template named `demo_example`.

The third argument is an array of template parameters/variables that should be available to the view. This array should generally be `key => value` pairs. The above example is passing two template params to the template. The `key` part of the array indicates the name of the variable available within the template. The `value` part of the array indicates the value.

So, if we had the following contents in the `demo_example` template:

```html
{$hello} {$world}
```

The template would output the following:

```plain
Hello world!
```

## Redirect reply

This reply is returned when you wish to redirect a user to a different URL after they have completed some sort of action.

A common use case here is after a user has submitted data through a form you may wish to redirect them to a different page, for example returning a user to a list of items. 

Here's an example of a typical controller action that performs a redirect:

{'fraction_non_alphanumeric': 0.06058832138153081, 'fraction_numerical': 0.0, 'mean_word_length': 4.2609699769053115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4300298', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1628, 'n_words': 1050}