Create a PHP Function
Learn to create a simple PHP function within a Symfony controller and modify the existing index method to display dynamic content on a new web page. This lesson guides you through adding and calling a testable function, preparing your application for subsequent PHPUnit tests.
We'll cover the following...
We'll cover the following...
In this lesson, we’ll create a PHP function and make our new web page use it. This function will be used for PHPUnit testing later on in the course.
Add a PHP function
First, let’s create a simple testable PHP function.
- In the widget below, find the
src/Controller/NewPageController.phpfile. - Add the new function.
public function personalMessage(): string
{
return "PHP is cool";
}