PHPStorm php代码缩进

发布于 2024-11-11 16:46:08 字数 995 浏览 3 评论 0原文

我需要像这样正确缩进这些代码块:

$this->render('rights', array(
    'admin' => $admin,
    'editor' => $editor,
    'author' => $author,
));

和小部件片段:

<?php $this->widget('zii.widgets.CMenu', array(
    'items' => array(
        array('label' => 'label', 'url' => 'url')
    )
)); ?>

使用默认的 PHPStorm 设置,它会像这样缩进此代码:

$this->render('rights', array(
                             'admin' => $admin,
                             'editor' => $editor,
                             'author' => $author,
                        ));

我转到“设置”->“代码样式”->“包装和大括号”并更改了以下选项:

  • 数组初始值设定项->多个(取消选中)
  • 方法调用参数时对齐 ->多个时对齐(取消选中)

结果是:

$this->render('rights', array(
        'admin' => $admin,
        'editor' => $editor,
        'author' => $author,
    ));

仍然不是我想要的样式,但这就是我设法完成的全部。您能指出我需要更改的选项吗?

I need these chunks of code to be indented properly like this:

$this->render('rights', array(
    'admin' => $admin,
    'editor' => $editor,
    'author' => $author,
));

and widget snippet:

<?php $this->widget('zii.widgets.CMenu', array(
    'items' => array(
        array('label' => 'label', 'url' => 'url')
    )
)); ?>

With default PHPStorm settings it indents this code like this:

$this->render('rights', array(
                             'admin' => $admin,
                             'editor' => $editor,
                             'author' => $author,
                        ));

I went to Settings->Code Style->Wrapping and Braces and changed following options:

  • Array initializer -> Align when multiple (uncheck)
  • Method call arguments -> Align when multiple (uncheck)

The result is:

$this->render('rights', array(
        'admin' => $admin,
        'editor' => $editor,
        'author' => $author,
    ));

Still not the style I want, but that's all I managed to accomplish. Can you please point me to the option I need to change?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

似梦非梦 2024-11-18 16:46:08

尝试选择所有代码并单击:
Ctrl + Alt + I
这是自动缩进快捷方式...

Try selecting all the code and clicking :
Ctrl + Alt + I
It's auto indentation shortcut ...

权谋诡计 2024-11-18 16:46:08

这似乎是一个已知问题。请观看/投票或添加您的评论。

It seems a to be a known issue. Please watch/vote or add your comments there.

吲‖鸣 2024-11-18 16:46:08

我发现取消选中以下选项可以解决我的问题:

偏好设置>编辑>代码风格> PHP>选项卡“包裹和大括号”>函数/构造函数调用参数 > 多行时对齐

这会更改以下代码:

var $numbers = $this->thing(array(
                                "one",
                                "two",
                                "three",
                                "four",
                                "five",
                                "six"
                            ));

格式如下:

var $numbers = $this->thing(array(
    "one",
    "two",
    "three",
    "four",
    "five",
    "six"
));

I've found that unchecking the following option solves the issue for me:

Preferences > Editor > Code Style > PHP > Tab 'Wrapping and Braces' > Function/constructor call arguments > Align when multiline

This changes the following code:

var $numbers = $this->thing(array(
                                "one",
                                "two",
                                "three",
                                "four",
                                "five",
                                "six"
                            ));

To be formatted like:

var $numbers = $this->thing(array(
    "one",
    "two",
    "three",
    "four",
    "five",
    "six"
));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文