「ver4/関数リファレンス/BcBaser contentsName」の版間の差分
提供: baserCMS公式ガイド
Katokaisya (トーク | 投稿記録) |
|||
(2人の利用者による、間の23版が非表示) | |||
行1: | 行1: | ||
− | |||
## 説明 | ## 説明 | ||
− | コンテンツを特定する文字列を出力する。 | + | コンテンツを特定する文字列を出力する。<br> |
+ | URLを元に、第一階層までの文字列をキャメルケースで出力します。<br /> | ||
− | + | 《例》<br /> | |
− | + | - トップページの場合 : Home<br /> | |
− | + | - about ページの場合 : About<br> | |
− | + | - エラーページの場合 : Error | |
− | + | ||
− | + | ||
− | + | ||
− | - トップページの場合 : Home | + | |
− | + | ||
− | - about ページの場合 : About | + | |
## 使い方 | ## 使い方 | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | $this->BcBaser->contentsName( $detail, [$options] ); | + | <?php $this->BcBaser->contentsName($detail, [$options]); ?> |
</syntaxhighlight> | </syntaxhighlight> | ||
行24: | 行18: | ||
(bool) $detail | (bool) $detail | ||
: 詳細モード true にした場合は、ページごとに一意となる文字列をキャメルケースで出力する | : 詳細モード true にした場合は、ページごとに一意となる文字列をキャメルケースで出力する | ||
− | + | :(例)http://xxx.xx/contact/index の場合、「ContactIndex」を取得 | |
− | + | : - 初期値:false | |
(array) $options | (array) $options | ||
: オプション | : オプション | ||
− | : | + | : - 初期値:array() |
− | + | :`home` : トップページの場合に出力する文字列(初期値: Home) | |
− | + | :`default` : ルート直下の下層ページの場合に出力する文字列(初期値: Default) | |
− | + | :`error` : エラーページの場合に出力する文字列(初期値: Error) | |
− | + | :`underscore` : キャメルケースではなくアンダースコア区切りで出力する(初期値: false) | |
− | + | ||
## 用例 | ## 用例 | ||
### 基本 | ### 基本 | ||
+ | bodyのidにコンテンツ名を指定する。 | ||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
行49: | 行43: | ||
### 応用 | ### 応用 | ||
+ | bodyのidに一意となる文字列をアンダースコア区切りで出力する。 | ||
####コード | ####コード | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
− | + | <body id="<?php $this->BcBaser->contentsName( true, array('underscore' => true)) ?>"> | |
</syntaxhighlight> | </syntaxhighlight> | ||
####出力 | ####出力 | ||
<syntaxhighlight lang="html5"> | <syntaxhighlight lang="html5"> | ||
− | + | <body id="contact_index"> | |
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
## 変更履歴 | ## 変更履歴 | ||
− | + | - [https://github.com/baserproject/basercms/blob/98c5d24daca66c38dfbd2b67c0ac85a3b5902b26/lib/Baser/View/Helper/BcBaserHelper.php#L1278 4.4.0] | |
− | # | + | |
− | + | ||
− | + | ||
##類似の関数 | ##類似の関数 | ||
− | + | - [getContentsName](/ver4/関数リファレンス/getContentsName) - コンテンツを特定する文字列を取得する | |
− | [ | + |
2020年10月19日 (月) 14:28時点における最新版
説明
コンテンツを特定する文字列を出力する。
URLを元に、第一階層までの文字列をキャメルケースで出力します。
《例》
- トップページの場合 : Home
- about ページの場合 : About
- エラーページの場合 : Error
使い方
<?php $this->BcBaser->contentsName($detail, [$options]); ?>
パラメータ
- (bool) $detail
- 詳細モード true にした場合は、ページごとに一意となる文字列をキャメルケースで出力する
- (例)http://xxx.xx/contact/index の場合、「ContactIndex」を取得
home
: トップページの場合に出力する文字列(初期値: Home)default
: ルート直下の下層ページの場合に出力する文字列(初期値: Default)error
: エラーページの場合に出力する文字列(初期値: Error)underscore
: キャメルケースではなくアンダースコア区切りで出力する(初期値: false)
用例
基本
bodyのidにコンテンツ名を指定する。
コード
<body id="<?php $this->BcBaser->contentsName() ?>">
出力
<body id="Contact">
応用
bodyのidに一意となる文字列をアンダースコア区切りで出力する。
コード
<body id="<?php $this->BcBaser->contentsName( true, array('underscore' => true)) ?>">
出力
<body id="contact_index">
変更履歴
類似の関数
- getContentsName - コンテンツを特定する文字列を取得する