Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
8c79c4f0
Commit
8c79c4f0
authored
Apr 24, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed typo
parent
264cf81e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
5 deletions
+35
-5
authorization.md
docs/guide/authorization.md
+1
-1
template.md
docs/guide/template.md
+23
-3
ViewRenderer.php
extensions/twig/ViewRenderer.php
+11
-1
No files found.
docs/guide/authorization.md
View file @
8c79c4f0
...
...
@@ -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
(
'update
Own
Post'
,
[
'post'
=>
$post
]))
{
// update post
}
```
...
...
docs/guide/template.md
View file @
8c79c4f0
...
...
@@ -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
...
...
extensions/twig/ViewRenderer.php
View file @
8c79c4f0
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment