「ver4/関数リファレンス/BcBaser getContentsName」の版間の差分
提供: baserCMS公式ガイド
行16: | 行16: | ||
## 使い方 | ## 使い方 | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | <?php $this->BcBaser->getContentsName( $detail , [$option] ); ?> | + | <?php $this->BcBaser->getContentsName( [$detail] , [$option] ); ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
行40: | 行40: | ||
## 用例 | ## 用例 | ||
### 基本 | ### 基本 | ||
+ | コンテンツ名取得し、echoで出力する。 | ||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | <?php echo $this->BcBaser->getContentsName( | + | <?php echo $this->BcBaser->getContentsName() ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
####出力 | ####出力 | ||
<syntaxhighlight lang="html5"> | <syntaxhighlight lang="html5"> | ||
− | + | Contact | |
</syntaxhighlight> | </syntaxhighlight> | ||
2018年10月24日 (水) 23:13時点における版
[このコンテンツは内容調整中です]
目次
説明
コンテンツを特定する文字列を取得します。
bodyタグ等にid属性として設定し、コンテンツごとに適用されるCSSを切り替えたりする場合に便利です。
URL を元に、第一階層までの文字列をキャメルケースで取得します。
(例)http://xxx.xx/contact/index の場合、「Contact」を取得
また、トップページの場合は「Home」、エラーページの場合は「Error」を出力します。
※オプションでアンダースコア表記にもできます。
使い方
<?php $this->BcBaser->getContentsName( [$detail] , [$option] ); ?>
パラメータ
- (bool) $detail
- true に設定するとページごとに一意となる文字列をキャメルケースで取得します。
- (例)http://xxx.xx/contact/index の場合、「ContactIndex」を取得
- 初期値:false
- (array) $options
- オプションを連想配列で指定する。
- - 初期値:array()
home
: トップページの場合に出力する文字列(初期値 : Home)default
: ルート直下の下層ページの場合に出力する文字列(初期値 : Default)error
: エラーページの場合に出力する文字列(初期値 : Error)underscore
: キャメルケースではなく、アンダースコア区切りで出力する(初期値 : false)
戻り値
(string)
用例
基本
コンテンツ名取得し、echoで出力する。
コード
<?php echo $this->BcBaser->getContentsName() ?>
出力
Contact
応用
コード
<body id="<?php echo $this->BcBaser->getContentsName(true) ?>">
出力
<body id="ContactIndex">