Skip to content

Instantly share code, notes, and snippets.

@gogl92
Last active February 22, 2018 15:27
Show Gist options
  • Save gogl92/dc2a17e8db0adf13b6ef04956d1b9e4a to your computer and use it in GitHub Desktop.
Save gogl92/dc2a17e8db0adf13b6ef04956d1b9e4a to your computer and use it in GitHub Desktop.
PHPStorm Yii2 Live Templates

Install

Just put it under your templates folder inside your

<templateSet group="Yii">
<template name="yrnd" value="return $this-&gt;render('view');" description="Yii2 Render View" toReformat="false" toShortenFQNames="true">
<context>
<option name="PHP" value="true" />
</context>
</template>
<template name="yaction" value="public function action$NAME$(){&#10; &#10;}" description="Creates Yii2 Action" toReformat="false" toShortenFQNames="true">
<variable name="NAME" expression="capitalize(String)" defaultValue="View" alwaysStopAt="true" />
<context>
<option name="PHP" value="true" />
</context>
</template>
<template name="yt" value="Yii::t()" description="Yii::t()" toReformat="true" toShortenFQNames="true">
<context>
<option name="PHP" value="true" />
</context>
</template>
<template name="sfield" value="&lt;?= $form-&gt;field($model, '$NAME$') ?&gt;" description="&lt;?= $form-&gt;field($model, 'name') ?&gt;" toReformat="false" toShortenFQNames="true">
<variable name="NAME" expression="camelCase(String)" defaultValue="$name" alwaysStopAt="true" />
<context>
<option name="HTML" value="true" />
</context>
</template>
<template name="btn_s" value=" &lt;?= Html::submitButton('$VALUE$', ['class' =&gt; 'btn btn-primary']) ?&gt;" description="&lt;?= Html::submitButton('Submit', ['class' =&gt; 'btn btn-primary']) ?&gt;" toReformat="false" toShortenFQNames="true">
<variable name="VALUE" expression="capitalize(String)" defaultValue="Enviar" alwaysStopAt="false" />
<context>
<option name="HTML" value="true" />
</context>
</template>
<template name="getbyid" value="$variable$ = $CLASS$::find()-&gt;where(['id' =&gt; $id$])-&gt;one();&#10;" description="$customer = Customer::find()-&gt;where(['id' =&gt; 1])-&gt;one();" toReformat="false" toShortenFQNames="true">
<variable name="variable" expression="camelCase(String)" defaultValue="$instance" alwaysStopAt="true" />
<variable name="CLASS" expression="classNameComplete()" defaultValue="$model" alwaysStopAt="true" />
<variable name="id" expression="camelCase(String)" defaultValue="$id" alwaysStopAt="true" />
<context>
<option name="PHP" value="true" />
</context>
</template>
<template name="ch_field" value="&lt;?= $form-&gt;field($model, '$ATTRIBUTE$')-&gt;checkbox(); ?&gt;" description="&lt;?= $form-&gt;field($model, 'population')-&gt;checkbox(); ?&gt;" toReformat="false" toShortenFQNames="true">
<variable name="ATTRIBUTE" expression="camelCase(String)" defaultValue="attribute" alwaysStopAt="true" />
<context>
<option name="HTML" value="true" />
</context>
</template>
</templateSet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment