「ver4/関数リファレンス/BcBaser isCurrentUrl」の版間の差分
提供: baserCMS公式ガイド
細 (1版 : 関数リファレンス→ver4) |
|||
行12: | 行12: | ||
## 使い方 | ## 使い方 | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | $this->BcBaser->isCurrentUrl($url) | + | <?php $this->BcBaser->isCurrentUrl($url); ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
行22: | 行22: | ||
## 戻り値 | ## 戻り値 | ||
− | ( | + | (bool) |
+ | : 同じURL場合には true を返す。 | ||
行28: | 行29: | ||
### 基本 | ### 基本 | ||
− | + | 現在のページが'''/news/'''と同じか判定する。 | |
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | <?php $this->BcBaser->isCurrentUrl('/news/') ?> | + | <?php |
+ | if( $this->BcBaser->isCurrentUrl('/news/') ) { | ||
+ | //true(/news/)の場合の処理 | ||
+ | } | ||
+ | ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ## 注 | ||
+ | 現在のページが'''http://localhost/news/'''の場合、以下の結果となります。 | ||
+ | isCurrentUrl('/news/')・・・true<br> | ||
+ | isCurrentUrl('/news')・・・false<br> | ||
+ | isCurrentUrl('news')・・・false<br> | ||
+ | isCurrentUrl('/news/index')・・・true | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
## 変更履歴 | ## 変更履歴 |
2018年12月4日 (火) 00:16時点における版
[このコンテンツは内容調整中です]
説明
指定したURLが現在のURLと同じかどうか判定する。
<比較例>
/news/ | /news/ ・・・○
/news | /news/ ・・・×
/news/ | /news/index ・・・○
使い方
<?php $this->BcBaser->isCurrentUrl($url); ?>
パラメータ
- (string) $url
- 比較対象URL
戻り値
- (bool)
- 同じURL場合には true を返す。
用例
基本
現在のページが/news/と同じか判定する。
コード
<?php if( $this->BcBaser->isCurrentUrl('/news/') ) { //true(/news/)の場合の処理 } ?>
注
現在のページがhttp://localhost/news/の場合、以下の結果となります。
isCurrentUrl('/news/')・・・true
isCurrentUrl('/news')・・・false
isCurrentUrl('news')・・・false
isCurrentUrl('/news/index')・・・true