Commit 8c79c4f0 by Alexander Makarov

Fixed typo

parent 264cf81e
......@@ -370,7 +370,7 @@ if (\Yii::$app->user->can('createPost')) {
To check the `updateOwnPost` permission, an extra parameter is required by the `AuthorRule` described before.
```php
if (\Yii::$app->user->can('updatePost', ['post' => $post])) {
if (\Yii::$app->user->can('updateOwnPost', ['post' => $post])) {
// update post
}
```
......
......@@ -50,15 +50,35 @@ or `$this->renderPartial()` controller calls:
echo $this->render('renderer.twig', ['username' => 'Alex']);
```
### Additional functions
### Additional syntax
Yii adds some extra syntax constructs additionally to standard Twig ones.
###
Yii adds the following construct to the standard Twig syntax:
{{registerAssetBundle('AppAsset')}} - Registers asset bundle of a given name
### Forms
```
{% set form = form_begin({ ... }) %}
{{ form.field(...) }}
{% form.end() %}
```
#### Getting URL for a route
There are two functions you can use for URLs:
```php
<a href="{{ path('blog/view', {'alias' : post.alias}) }}">{{ post.title }}</a>
<a href="{{ url('blog/view', {'alias' : post.alias}) }}">{{ post.title }}</a>
```
Internally, the `path()` function calls Yii's `Url::to()` method.
`path` generates relative URL while `url` generates absolute one. Internally both are using [[\yii\helpers\Url]].
### Additional variables
......
......@@ -23,7 +23,8 @@ use yii\helpers\Url;
class ViewRenderer extends BaseViewRenderer
{
/**
* @var string the directory or path alias pointing to where Twig cache will be stored.
* @var string the directory or path alias pointing to where Twig cache will be stored. Set to false to disable
* templates cache.
*/
public $cachePath = '@runtime/Twig/cache';
/**
......@@ -114,6 +115,11 @@ class ViewRenderer extends BaseViewRenderer
$this->setLexerOptions($this->lexerOptions);
}
// $this->addFunctions([
// 'rot13' => 'str_rot13',
// 'jsonEncode' => '\yii\helpers\Json::encode',
// ]);
// Adding global 'void' function (usage: {{void(App.clientScript.registerScriptFile(...))}})
$this->twig->addFunction('void', new \Twig_Function_Function(function ($argument) {
}));
......@@ -122,6 +128,10 @@ class ViewRenderer extends BaseViewRenderer
return Url::to(array_merge([$path], $args));
}));
$this->twig->addFunction('url', new \Twig_Function_Function(function ($path, $args = []) {
return Url::to(array_merge([$path], $args), true);
}));
$this->twig->addGlobal('app', \Yii::$app);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment