O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Customize JavaScript and CSS

As mentioned before, in this chapter, you will discover how to use frontend interaction. Using JavaScript and CSS is fundamental to customize frontend output.

Differently from Yii1, where calling JavaScript and CSS scripts and files was done using the Yii::app() singleton, in the new framework version, Yii2, this task is part of the yii\web\View class.

There are two ways to call JavaScript or CSS: either directly passing the code to be executed or passing the path file.

Note

When passing the code directly to be executed, we will use the Heredoc syntax provided by PHP to avoid handling strings escaping.

The registerJs() function allows us to execute the JavaScript code with three parameters:

  • The first parameter is the JavaScript ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required