Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An overview of PhpStorm navigation and an introduction to navigation to classes, interfaces, and Trait

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the "Overview of PhpStorm navigation and navigation to classes, interfaces, Trait introduction" related knowledge, in the actual case operation process, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

Overview

In the daily use of the code editor, one of the most frequent requirements is the ability to quickly and globally navigate to specified classes, files, methods, and lines, which can be achieved in PhpStorm in two ways.

One is to click Navigate in the menu bar, and then select the corresponding global navigation in the drop-down box. Class represents the class, File represents the file, Symbol represents the symbol / tag (which can be used to navigate to the specified variable, method), and Line represents the line (which needs to be operated in a specific file).

The other is through the shortcut keys, the corresponding shortcut keys have been marked on the right side of the drop-down box navigation options in the menu bar above, and we can demonstrate the shortcut keys in the Mac system as an example (the Windows operation is similar, but the shortcut keys are different).

Navigate to classes, interfaces, Trait

Open a newly installed Laravel project. Take the User class that comes with it as an example. To navigate to this class, you can use the shortcut key Command + O to open the navigation window, enter User in the input box for global fuzzy matching of the class name, and then select the class you want to navigate in the drop-down option:

The file containing the User class will be opened:

It's the same with navigating to other classes, and I won't repeat the demonstration here. In addition to the project code, you can also navigate to all the third-party expansion pack code in the vendor library managed by Composer, for example, we want to view the parent class Model of User:

In addition, navigating to the specified interface and Trait share the function of navigating to the specified class. For example, if we enter Authenticatable in the class navigation input box, the corresponding interface and Trait will be listed:

Navigate to a file

In modern PHP projects that follow the PSR-4 auto-load specification, the class name and file name are the same, so navigating to the class means navigating to the corresponding file, but for some PHP files that do not contain any classes, you still need to jump by navigating to the file function, such as applying initialization / startup files, configuration files, routing files, and files that define PHP helper functions.

We can open the operation interface of navigating to the file through the shortcut key Shift + Command + P file. Suppose we want to open the database configuration file of the Laravel project, we can enter database in the input box for global fuzzy matching of the file name, and then select the file we want to open in the drop-down box:

You can jump to the corresponding database.php configuration file:

If you want to open the helpers.php file that defines the helper function of Laravel, you can do it exactly the same way, just enter the corresponding file name in the navigation input box:

Navigate to properties, methods

In addition to class names and files, PhpStorm also supports finer-grained navigation of PHP properties and methods. We open the corresponding navigation interface through the shortcut key Option + Command + O. Suppose we want to add a global middleware to the Kernel class of the application code. You can enter middleware in the input box and jump to this attribute to set it:

This method is also suitable for global navigation of variable names:

Navigating to the specified class / Trait member method or independent PHP function also operates in the same interface. For example, if you want to see how the paging method that comes with Laravel is implemented at the bottom, you can type paginate in the input box, and then select the method implementation we want to view:

For example, to see how the view function that comes with Laravel is implemented, type view in the input box and select the method you want to navigate:

Jump to rows, columns

Finally, in the open current file, you can open the row and column navigation interface through Command + L, and enter the row number and column number to navigate to, where rows and columns are distinguished and parsed by "row number: column number":

The column number is generally not set, and the default value is 1.

In the graphical UI interface, there is usually little need to jump to the specified rows and columns, and we can quickly navigate to the specified location through the mouse and touch screen.

Summary navigation

For the navigation of classes, files, attributes and methods, in addition to using their respective keyboard shortcuts and operation interfaces in the above ways, in PhpStorm, you can also open the summary navigation operation interface (the corresponding function is called Search Everywhere) through Shift + Shift shortcut keys (press the Shift key twice). With one input, you can globally match all relevant classes, files, properties and methods:

Is it very convenient? It is called "Search Everywhere" because in addition to these navigation features, you can also quickly locate the PhpStorm system settings through Actions (which we will discuss separately later). In other words, everything you want to search can be done through this input box, and it is for this reason that the keyboard shortcuts corresponding to this function are at the top of the list of PhpStorm default boot interfaces:

Any operation we need to do every day, whether it is looking for files, looking for code, or setting up the system, can jump quickly through the Shift + Shift outbound navigation interface, which will become the shortcut key operation that you use PhpStorm most frequently.

Context navigation

The above navigation is global navigation. If you want to navigate in context in a specific code snippet, take the posts method of the User model class as an example:

Public function posts ()

{

Return $this- > hasMany (Post::class, 'user_id')

}

If you want to view the implementation code for the hasMany method, you can press and hold the Command key (Ctrl under Windows), and then click the hasMany method on the mouse / touchscreen to jump to the corresponding method implementation code:

This is the end of the introduction to "Overview of PhpStorm navigation and introduction to classes, interfaces, and Trait". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report