1. Because the frontend has separate pages for mobile and desktop devices, I need to detect whether the device is mobile in PHP 7.4, and then render different template files.
2. Reference: Mobile-Detect. I can only use the latest 3.* version because I am currently using PHP 7.4, and its 4.* version requires PHP 8 or above. See Figure 1.

3. Mobile Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. Under Modules, plugins, ports -> Yii Framework on the page, I found that the implemented Yii2 extensions have not been updated for about 5 years and depend on “mobiledetect/mobiledetectlib”: “~2.8”. I ultimately decided to use “mobiledetect/mobiledetectlib”: “^3.74”. I configured composer.json and installed the update. See Figure 2.

{
"require": {
"mobiledetect/mobiledetectlib": "^3.74"
}
}
PS C:\wwwroot\object\src> composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update `.
- Required package "mobiledetect/mobiledetectlib" is not present in the lock file.
This usually happens when composer files are incorrectly merged or the composer.json file is manually edited.
Read more about correctly resolving merge conflicts https://getcomposer.org/doc/articles/resolving-merge-conflicts.md
and prefer using the "require" command over editing the composer.json file directly https://getcomposer.org/doc/03-cli.md#require-r
PS C:\wwwroot\object\src> composer update mobiledetect/mobiledetectlib
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking mobiledetect/mobiledetectlib (3.74.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Downloading mobiledetect/mobiledetectlib (3.74.3)
- Installing mobiledetect/mobiledetectlib (3.74.3): Extracting archive
Package codeception/phpunit-wrapper is abandoned, you should avoid using it. No replacement was suggested.
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
59 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
PS C:\wwwroot\object\src>
4. Then, I implemented the following in the controller:
use Detection\MobileDetect;
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
$detect = new MobileDetect();
// $deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
if ($detect->isMobile()) {
return $this->render('index_mobile');
}
return $this->render('index');
}
