yiisoft / yiisoft/app

Standardize web app folder and file naming (Action.php vs. FolderNameHandler.php)

Open
#426 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:under discussion
Dominant language
PHP
Stars
381
Forks
68
Avg merge
1h 10m
Merged PRs (30d)
1

Description

Proposed new feature or change

While learning my way around the Yii3 starter app, I found the naming of web entry points a bit confusing to follow. In the same project, we have two different styles for the same type of file:

HomePage: src/Web/HomePage/Action.php

NotFound: src/Web/NotFound/NotFoundHandler.php

As a new user, this made it difficult for me to tell what is a "framework requirement" and what is just a naming choice.
How this affects the learning curve:

"Is 'Action' a magic word?" When I see Action.php used repeatedly, my first thought is that the framework requires this specific name to work. It wasn't until I saw NotFoundHandler.php that I realized I could name these files whatever I wanted. Standardizing this would make it much clearer that these are just standard PHP classes.

Confusion in the Routing Logic The router uses ->action(Action::class). Seeing the word "action" used as a method, a class name, and a filename all at once made it hard for me to visualize the flow of data. Using a unique name like HomePageHandler makes it much easier to see the difference between the Router's command and my own code.

Difficulty Tracking Code While trying to understand how different pages connect, I found it hard to keep track of which file I was looking at. When my editor tabs all say Action.php, I have to keep checking the namespace just to remember which page's logic I'm editing.

The Suggestion: Follow the NotFoundHandler pattern

I think the NotFoundHandler approach is a much better "teaching tool" for the demo app. It shows exactly what the file is for and makes the routes.php file much easier to read without needing to alias every import.

Proposed Standard:

  • Folder: src/Web/HomePage/
  • Logic File: HomePageHandler.php (Descriptive and unique)
  • View File: template.php

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare src/Web/HomePage/Action.php with src/Web/NotFound/NotFoundHandler.php, then inspect routes.php and the referenced classes. Follow the proposed HomePageHandler naming pattern, update route references, and keep template.php in the stated folder. Done means the web entry points use one descriptive naming convention and routes.php remains readable.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.