Pictnotes メインイメージ

お仕事メモ

contentsName関数の挙動について

contentsNameの挙動を整理



contentsName関数は、
http://basercms.net/reference_3/archives/65
 

によれば、
[contentsName] コンテンツを特定するIDを出力する
と、cssとかの切り替えに便利なのですが、デフォルトがキャメルケースなので、それを小文字にしたいばあいは
<body id="<?php $this->BcBaser->contentsName(false, array('underscore'=>true)) ?>">
とすると、小文字で出力する事ができる。第2引数の「underscore」は通常アンダースコアつながりというオプションなのだが、こちらを指定することで、大文字にする事を回避する事ができます。

http://basercms.net/reference/archives
を例にとると、

<body id="<?php $this->BcBaser->contentsName() ?>">
引数をあたえない場合
<body id="Reference">
と出力される。

<body id="<?php $this->BcBaser->contentsName(true) ?>">
第一引数を trueに
<body id="ReferenceArchives">
と出力される。

<body id="<?php $this->BcBaser->contentsName(false, array('underscore'=>true)) ?>">
第一引数を falseに underscoreをtrueに
<body id="reference">
と出力される。

<body id="<?php $this->BcBaser->contentsName(true, array('underscore'=>true)) ?>">
第一引数を trueに underscoreをtrueに
<body id="reference_archives">
と出力される。

ちなみに、
http://basercms.net/reference_3/archives/65
のURLの場合、
<body id="<?php $this->BcBaser->contentsName() ?>">
引数をあたえない場合
<body id="Reference3
">
と、アンダースコアは削除され3は大文字がないのでそのままつながります。

<body id="<?php $this->BcBaser->contentsName(true) ?>">
第一引数を trueに
<body id="Reference3Archives65">
と、なります。

<body id="<?php $this->BcBaser->contentsName(false, array('underscore'=>true)) ?>">
第一引数を falseに underscoreをtrueに
<body id="reference_3">
と出力される。

<body id="<?php $this->BcBaser->contentsName(true, array('underscore'=>true)) ?>">
第一引数を trueに underscoreをtrueに
<body id="reference_3_archives_65">
と出力される。

URLの中にアンダースコアや数字が入っていると思った通りの挙動にならないかもしれないので注意が必要です。

とりあえず、僕のid指定とかは小文字だけで指定してるぜ!!
ってかたは、第2引数を「array('underscore'=>true)」にして対応してくださいませ。

 





 

 

baserCMS   2014/02/14   admin