PHPStorm php-code indentation - phpstorm

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?

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

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

I think this will help you in formatting
Your code
https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/8

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"
));

Related

How can I implement a random page button in MediaWiki?

I made the random page button by adding the following code to the Template.php skin file.
Html::rawElement( 'a', [
'id' => 'random',
'class' => 'random',
'href' => './index.php?title=Special:Random'
] )
But I don't like the 'href' part. Is there a way to write it like 'href' => $this->data['nav_urls']['mainpage']['href']?
I'm not sure, for what exactly you want to use it, however, the easiest part to replace the static linking to index.php?title=Special:Random would be to use the title object and let it generate a link for you. In your case something like this:
SpecialPage::getTitleFor( 'Random' )->getLinkURL()
in your full example:
Html::rawElement( 'a', [
'id' => 'random',
'class' => 'random',
'href' => SpecialPage::getTitleFor( 'Random' )->getLinkURL()
] );

How to make active item of SideNav in another style?

I want the items in my SideNav by Kartik in the yii2 app to change the color when it is active(was clicked and open).
Sorry, I am pretty new for PHP and Yii and the question might be seen obvious but I really stack here.
I have already tried to use the "active" option that is explained in the documentation but it doesn't work. It doesn't show any error but is not working. I have a file adminMenu.php where the SideNav is written. and the panel.php view file where I showing it.
Also, I tried to add echo
$this->render('adminMenu'['currentPage'=>'admin/personal']);
but it shows error and thus I comment it for now.
adminMenu.php:
class adminMenu extends Widget{
public function init(){
$curentpage = Yii::$app->controller->id ;
parent::init();
ob_start();
echo SideNav::widget([
'type' => SideNav::TYPE_PRIMARY,
'headingOptions' => ['class'=>'head-style'],
'items' => [
['label' => 'Personal',
'url' => ['/admin/personal'],
'active' => ($curentpage == 'admin/personal')],
['label' => 'Clients',
'url' => ['/admin/clients'],
'active' => ($curentpage == 'admin/clients')],
...
]);
panel.php:
if(\Yii::$app->user->can('Admin')){
echo adminMenu::widget();
//echo $this->render('adminMenu'['currentPage'=>'admin/personal']);
}
i think that you mistake is in this line
$curentpage = Yii::$app->controller->id;
Yii::$app->controller->id only return the name of your controller , in this casi will be "admin" then you compare "admin" equals "controller/action" ('admin/personal') this never will be equals .
To do this , you can do a concat the actual controller and the actual action like this :
$curentpage = Yii::$app->controller->id.'/'.Yii::$app->controller->action->id;
and the comparation will be success and the "active" class add to you sidebar

Why my listview not found any record in yii2?

I have a dataprovider to search a world but my listview does not display any record? How can i send this query object to listview?
every thing in my webpage is worked very good but at the output my list view show "not found any result" this mean my list view code is no have problem . problem is in my dataprovider and this query beacuse i customize that
my controller:
$query = new Query();
$dataProvidersearch=new ActiveDataProvider([
'query'=>$query->from('tbl_post')->Where(['like', 'title', $search])-
>andWhere(['like', 'en_title', $search])->andWhere(['like', 'content', $search])->andWhere(['like', 'en_content', $search]),
]);
this is my list view in my view:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$posts,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
]);
I'm not sure you have enough code here for someone to help. Even something simple like a listview could consist of a view, a controller, and two model files and your code could be failing at any of these points. You may have simply forgot to include the listview library at the top of your view, but we can't see that in your current example.
What I would recommend is using Gii to generate a listview. It is simple to do and once you have it created, you can study the code to see where you went wrong. You can see how to get started generating code with Gii here: http://www.yiiframework.com/doc-2.0/guide-start-gii.html
ANSWER FROM COMMENTS: Replace andWhere with orWhere, no results are found because no record can match 'title' and 'en_title' and 'content' and 'en_content'.
You are submitting $posts as 'dataProvider' while it should be dataProvidersearch
Instead of:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$posts,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
];
Should be:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$dataProvidersearch,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
];

Yii2 kartik detailview hide label

If I'm doing 'label' => false, it is still showing the empty cell of the label. Is it possible completely not to render label cell somehow? Many thanks!
UPDATE: 'labelColOptions' => ['hidden' => true] works!
You can use visible property :
For example,
[
'attribute' => 'name',
'value' => whatever,
'visible' => (!empty($model->name)),
]

PhpStorm function with array parameter alignment

I have this:
$client->setHeaders(array(
'Date' => $date,
'X-Amzn-Authorization' => $authKey,
));
PhpStorm wants to autoformat it as this:
$client->setHeaders(
array(
'Date' => $date,
'X-Amzn-Authorization' => $authKey,
));
Which settings do I need to change in the code format options in order to get the former not the latter?
go to Setttings > Editor > Code style > PHP
Select the Wrapping and Braces tab
Under the "Function call arguments" Category uncheck "New Line after '('"