| yii\base\View has special $params property.
For example it's used for building breadcrumbs in default generated CRUD code templates with Gii.
You can set it like this before rendering:
use Yii;
Yii::$app->view->params['customParam'] = 'customValue';
Inside a controller you can set it like this:
$this->view->params['customParam'] = 'customValue';
Then it will be available in views (including main layout):
/* @var $this yii\web\View */
echo $this->params['customParam'];
|
Expand
Collapse
(18 lines)
https://snipt.net/embed/3269fd232e5f448ef5ec6923944c4064/
/raw/3269fd232e5f448ef5ec6923944c4064/
3269fd232e5f448ef5ec6923944c4064
text
Text only
18
2025-04-03T15:57:51
True
False
False
Jan 14, 2017 at 08:14 PM
/api/public/snipt/8/
passing-values-to-layout-and-other-views
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a>
<a href="#L-2"> 2</a>
<a href="#L-3"> 3</a>
<a href="#L-4"> 4</a>
<a href="#L-5"> 5</a>
<a href="#L-6"> 6</a>
<a href="#L-7"> 7</a>
<a href="#L-8"> 8</a>
<a href="#L-9"> 9</a>
<a href="#L-10">10</a>
<a href="#L-11">11</a>
<a href="#L-12">12</a>
<a href="#L-13">13</a>
<a href="#L-14">14</a>
<a href="#L-15">15</a>
<a href="#L-16">16</a>
<a href="#L-17">17</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>yii\base\View has special $params property.
</span><span id="L-2"><a name="L-2"></a>
</span><span id="L-3"><a name="L-3"></a>For example it's used for building breadcrumbs in default generated CRUD code templates with Gii.
</span><span id="L-4"><a name="L-4"></a>
</span><span id="L-5"><a name="L-5"></a>You can set it like this before rendering:
</span><span id="L-6"><a name="L-6"></a>
</span><span id="L-7"><a name="L-7"></a>use Yii;
</span><span id="L-8"><a name="L-8"></a>
</span><span id="L-9"><a name="L-9"></a>Yii::$app->view->params['customParam'] = 'customValue';
</span><span id="L-10"><a name="L-10"></a>Inside a controller you can set it like this:
</span><span id="L-11"><a name="L-11"></a>
</span><span id="L-12"><a name="L-12"></a>$this->view->params['customParam'] = 'customValue';
</span><span id="L-13"><a name="L-13"></a>Then it will be available in views (including main layout):
</span><span id="L-14"><a name="L-14"></a>
</span><span id="L-15"><a name="L-15"></a>/* @var $this yii\web\View */
</span><span id="L-16"><a name="L-16"></a>
</span><span id="L-17"><a name="L-17"></a>echo $this->params['customParam'];
</span></pre></div>
</td></tr></table>
yii
| git fetch --all
git reset --hard origin/master
git reset --hard ascend/master
Better to discard changes:
git checkout -- .
Remove all untracked:
git clean -fd
|
Expand
Collapse
(10 lines)
https://snipt.net/embed/83e604a1f31d49dd00b3d08c109a13ce/
/raw/83e604a1f31d49dd00b3d08c109a13ce/
83e604a1f31d49dd00b3d08c109a13ce
text
Text only
10
2025-04-02T01:11:58
True
False
False
/api/public/snipt/7/
hard-pull-overwrite
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a>
<a href="#L-2">2</a>
<a href="#L-3">3</a>
<a href="#L-4">4</a>
<a href="#L-5">5</a>
<a href="#L-6">6</a>
<a href="#L-7">7</a>
<a href="#L-8">8</a>
<a href="#L-9">9</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git fetch --all
</span><span id="L-2"><a name="L-2"></a>git reset --hard origin/master
</span><span id="L-3"><a name="L-3"></a>git reset --hard ascend/master
</span><span id="L-4"><a name="L-4"></a>
</span><span id="L-5"><a name="L-5"></a>Better to discard changes:
</span><span id="L-6"><a name="L-6"></a>git checkout -- .
</span><span id="L-7"><a name="L-7"></a>
</span><span id="L-8"><a name="L-8"></a>Remove all untracked:
</span><span id="L-9"><a name="L-9"></a>git clean -fd
</span></pre></div>
</td></tr></table>
git
| \yii\db\Expression('NOW()')
use yii\db\Expression;
$model->date_created=new Expression('NOW()');
|
https://snipt.net/embed/820288349a0714bd67714c28aba55eb1/
/raw/820288349a0714bd67714c28aba55eb1/
820288349a0714bd67714c28aba55eb1
text
Text only
4
2025-04-03T15:34:55
True
False
False
/api/public/snipt/6/
yii-sql-expression
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a>
<a href="#L-2">2</a>
<a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>\yii\db\Expression('NOW()')
</span><span id="L-2"><a name="L-2"></a>use yii\db\Expression;
</span><span id="L-3"><a name="L-3"></a>$model->date_created=new Expression('NOW()');
</span></pre></div>
</td></tr></table>
yii
| function($url, $row_model) use ($model)
|
https://snipt.net/embed/30d3589de8c7affcb5cfef5e4982a1e7/
/raw/30d3589de8c7affcb5cfef5e4982a1e7/
30d3589de8c7affcb5cfef5e4982a1e7
text
Text only
2
2025-04-03T15:35:57
True
False
False
Jan 02, 2017 at 08:38 PM
/api/public/snipt/5/
pass-param-to-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>function($url, $row_model) use ($model)
</span></pre></div>
</td></tr></table>
| $js = <<<JS
JS;
$this->registerJs($js);
|
https://snipt.net/embed/2f79983f62415f088c8e671f8b27c6ac/
/raw/2f79983f62415f088c8e671f8b27c6ac/
2f79983f62415f088c8e671f8b27c6ac
text
Text only
6
2025-04-03T15:46:16
True
False
False
/api/public/snipt/4/
register-js-ca3f2a62
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a>
<a href="#L-2">2</a>
<a href="#L-3">3</a>
<a href="#L-4">4</a>
<a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>$js = <<<JS
</span><span id="L-2"><a name="L-2"></a>
</span><span id="L-3"><a name="L-3"></a>JS;
</span><span id="L-4"><a name="L-4"></a>
</span><span id="L-5"><a name="L-5"></a>$this->registerJs($js);
</span></pre></div>
</td></tr></table>
yii
| event.preventDefault();
event.stopImmediatePropagation();
|
https://snipt.net/embed/e0d6ba7a16a58bd79fc4fe2c29afda2f/
/raw/e0d6ba7a16a58bd79fc4fe2c29afda2f/
e0d6ba7a16a58bd79fc4fe2c29afda2f
text
Text only
3
2025-04-03T15:36:29
True
False
False
Dec 28, 2016 at 12:09 AM
/api/public/snipt/3/
jquery-form-prevent-submit
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a>
<a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>event.preventDefault();
</span><span id="L-2"><a name="L-2"></a>event.stopImmediatePropagation();
</span></pre></div>
</td></tr></table>
jquery
| git config credential.helper store
Home director
.git-credentials
https://jbmckee:KewlKat-1bi@bitbucket.org
ttps://bigal-master-dev:KewlAl91@bitbucket.org
.gitconfig
# This is Git's per-user configuration file.
[user]
# Please adapt and uncomment the following lines:
name = JB
email = server@jbmckee.com
[credential]
helper = store
[push]
default = simple
|
Expand
Collapse
(18 lines)
https://snipt.net/embed/93dc0e8c90a07232de92b2932fdfa032/
/raw/93dc0e8c90a07232de92b2932fdfa032/
93dc0e8c90a07232de92b2932fdfa032
text
Text only
18
2025-03-28T14:01:58
True
False
False
/api/public/snipt/2/
store-git-password
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a>
<a href="#L-2"> 2</a>
<a href="#L-3"> 3</a>
<a href="#L-4"> 4</a>
<a href="#L-5"> 5</a>
<a href="#L-6"> 6</a>
<a href="#L-7"> 7</a>
<a href="#L-8"> 8</a>
<a href="#L-9"> 9</a>
<a href="#L-10">10</a>
<a href="#L-11">11</a>
<a href="#L-12">12</a>
<a href="#L-13">13</a>
<a href="#L-14">14</a>
<a href="#L-15">15</a>
<a href="#L-16">16</a>
<a href="#L-17">17</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>git config credential.helper store
</span><span id="L-2"><a name="L-2"></a>
</span><span id="L-3"><a name="L-3"></a>Home director
</span><span id="L-4"><a name="L-4"></a>.git-credentials
</span><span id="L-5"><a name="L-5"></a>https://jbmckee:KewlKat-1bi@bitbucket.org
</span><span id="L-6"><a name="L-6"></a>ttps://bigal-master-dev:KewlAl91@bitbucket.org
</span><span id="L-7"><a name="L-7"></a>
</span><span id="L-8"><a name="L-8"></a>.gitconfig
</span><span id="L-9"><a name="L-9"></a># This is Git's per-user configuration file.
</span><span id="L-10"><a name="L-10"></a>[user]
</span><span id="L-11"><a name="L-11"></a># Please adapt and uncomment the following lines:
</span><span id="L-12"><a name="L-12"></a> name = JB
</span><span id="L-13"><a name="L-13"></a> email = server@jbmckee.com
</span><span id="L-14"><a name="L-14"></a>[credential]
</span><span id="L-15"><a name="L-15"></a> helper = store
</span><span id="L-16"><a name="L-16"></a>[push]
</span><span id="L-17"><a name="L-17"></a> default = simple
</span></pre></div>
</td></tr></table>
git
| grep -lr '<<<<<<<' . | xargs git checkout --theirs
|
https://snipt.net/embed/cca86c8c58527986414eefaa4ff6859e/
/raw/cca86c8c58527986414eefaa4ff6859e/
cca86c8c58527986414eefaa4ff6859e
text
Text only
1
2025-04-03T15:32:36
True
False
False
Dec 20, 2016 at 08:59 PM
/api/public/snipt/1/
git-merge-conflicts
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>grep -lr '<<<<<<<' . | xargs git checkout --theirs
</span></pre></div>
</td></tr></table>
git
| var sql = "SELECT * from addresses";
new Promise(function (resolve, reject) {
JwApp.db.executeSql(sql, [], function (resultSet) {
console.log('Length: '+resultSet.rows.length);
for(var i = 0; i < resultSet.rows.length; i++) {
results[resultSet.rows.item(i).id] = resultSet.rows.item(i);
}
console.log(results);
resolve(results);
}, function(error) {
console.log('SELECT error: ' + error.message);
reject(error.message);
})
})
.then(function (res) {
console.log('Execuited Then');
console.log(res);
})
.catch(function (res) {
console.log('Execuited Then Reject');
console.log('SQL error: '+res);
});
|
Expand
Collapse
(25 lines)
https://snipt.net/embed/b8f84e331691e27497e9da6248bc4b86/
/raw/b8f84e331691e27497e9da6248bc4b86/
b8f84e331691e27497e9da6248bc4b86
text
Text only
25
2025-04-01T06:54:46
True
False
False
/api/public/snipt/147698/
javascript-promise
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a>
<a href="#L-2"> 2</a>
<a href="#L-3"> 3</a>
<a href="#L-4"> 4</a>
<a href="#L-5"> 5</a>
<a href="#L-6"> 6</a>
<a href="#L-7"> 7</a>
<a href="#L-8"> 8</a>
<a href="#L-9"> 9</a>
<a href="#L-10">10</a>
<a href="#L-11">11</a>
<a href="#L-12">12</a>
<a href="#L-13">13</a>
<a href="#L-14">14</a>
<a href="#L-15">15</a>
<a href="#L-16">16</a>
<a href="#L-17">17</a>
<a href="#L-18">18</a>
<a href="#L-19">19</a>
<a href="#L-20">20</a>
<a href="#L-21">21</a>
<a href="#L-22">22</a>
<a href="#L-23">23</a>
<a href="#L-24">24</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> var sql = "SELECT * from addresses";
</span><span id="L-2"><a name="L-2"></a> new Promise(function (resolve, reject) {
</span><span id="L-3"><a name="L-3"></a> JwApp.db.executeSql(sql, [], function (resultSet) {
</span><span id="L-4"><a name="L-4"></a> console.log('Length: '+resultSet.rows.length);
</span><span id="L-5"><a name="L-5"></a>
</span><span id="L-6"><a name="L-6"></a> for(var i = 0; i < resultSet.rows.length; i++) {
</span><span id="L-7"><a name="L-7"></a> results[resultSet.rows.item(i).id] = resultSet.rows.item(i);
</span><span id="L-8"><a name="L-8"></a> }
</span><span id="L-9"><a name="L-9"></a>
</span><span id="L-10"><a name="L-10"></a> console.log(results);
</span><span id="L-11"><a name="L-11"></a> resolve(results);
</span><span id="L-12"><a name="L-12"></a> }, function(error) {
</span><span id="L-13"><a name="L-13"></a> console.log('SELECT error: ' + error.message);
</span><span id="L-14"><a name="L-14"></a> reject(error.message);
</span><span id="L-15"><a name="L-15"></a> })
</span><span id="L-16"><a name="L-16"></a> })
</span><span id="L-17"><a name="L-17"></a> .then(function (res) {
</span><span id="L-18"><a name="L-18"></a> console.log('Execuited Then');
</span><span id="L-19"><a name="L-19"></a> console.log(res);
</span><span id="L-20"><a name="L-20"></a> })
</span><span id="L-21"><a name="L-21"></a> .catch(function (res) {
</span><span id="L-22"><a name="L-22"></a> console.log('Execuited Then Reject');
</span><span id="L-23"><a name="L-23"></a> console.log('SQL error: '+res);
</span><span id="L-24"><a name="L-24"></a> });
</span></pre></div>
</td></tr></table>
angular, ionic, javascript
| var sql = "SELECT id FROM streets WHERE territory_id = ? AND md5checksum = ?"
JwApp.db.executeSql(sql, [JwApp.working_territory, street_md5], function (resultSet) {
if (resultSet.rows.length) {
street_id = resultSet.rows.item(0).id;
for(var i = 0; i < resultSet.rows.length; i++) {
results[resultSet.rows.item(i).id] = resultSet.rows.item(i);
}
}
else {
console.log('No records returned.');
}
},
function (error) {
console.log('SELECT Street error: ' + error.message);
});
|
Expand
Collapse
(17 lines)
https://snipt.net/embed/c4d85f21d90fd616c1a8497c99c86115/
/raw/c4d85f21d90fd616c1a8497c99c86115/
c4d85f21d90fd616c1a8497c99c86115
text
Text only
17
2025-03-29T11:09:41
True
False
False
Sep 04, 2016 at 11:25 PM
/api/public/snipt/147697/
execute-db
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a>
<a href="#L-2"> 2</a>
<a href="#L-3"> 3</a>
<a href="#L-4"> 4</a>
<a href="#L-5"> 5</a>
<a href="#L-6"> 6</a>
<a href="#L-7"> 7</a>
<a href="#L-8"> 8</a>
<a href="#L-9"> 9</a>
<a href="#L-10">10</a>
<a href="#L-11">11</a>
<a href="#L-12">12</a>
<a href="#L-13">13</a>
<a href="#L-14">14</a>
<a href="#L-15">15</a>
<a href="#L-16">16</a>
<a href="#L-17">17</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a> var sql = "SELECT id FROM streets WHERE territory_id = ? AND md5checksum = ?"
</span><span id="L-2"><a name="L-2"></a> JwApp.db.executeSql(sql, [JwApp.working_territory, street_md5], function (resultSet) {
</span><span id="L-3"><a name="L-3"></a> if (resultSet.rows.length) {
</span><span id="L-4"><a name="L-4"></a> street_id = resultSet.rows.item(0).id;
</span><span id="L-5"><a name="L-5"></a>
</span><span id="L-6"><a name="L-6"></a> for(var i = 0; i < resultSet.rows.length; i++) {
</span><span id="L-7"><a name="L-7"></a> results[resultSet.rows.item(i).id] = resultSet.rows.item(i);
</span><span id="L-8"><a name="L-8"></a> }
</span><span id="L-9"><a name="L-9"></a>
</span><span id="L-10"><a name="L-10"></a> }
</span><span id="L-11"><a name="L-11"></a> else {
</span><span id="L-12"><a name="L-12"></a> console.log('No records returned.');
</span><span id="L-13"><a name="L-13"></a> }
</span><span id="L-14"><a name="L-14"></a> },
</span><span id="L-15"><a name="L-15"></a> function (error) {
</span><span id="L-16"><a name="L-16"></a> console.log('SELECT Street error: ' + error.message);
</span><span id="L-17"><a name="L-17"></a> });
</span></pre></div>
</td></tr></table>
angular, ionic