BcBaserHelper::getContentsName PHP Метод

getContentsName() публичный Метод

URL を元に、第一階層までの文字列をキャメルケースで取得する 《利用例》 $this->BcBaser->contentsName() 《出力例》 - トップページの場合 : Home - about ページの場合 : About
public getContentsName ( boolean $detail = false, array $options = [] ) : string
$detail boolean 詳細モード true にした場合は、ページごとに一意となる文字列をキャメルケースで取得する(初期値 : false)
$options array オプション(初期値 : array()) - `home` : トップページの場合に出力する文字列(初期値 : Home) - `default` : ルート直下の下層ページの場合に出力する文字列(初期値 : Default) - `error` : エラーページの場合に出力する文字列(初期値 : Error) - `underscore` : キャメルケースではなく、アンダースコア区切りで出力する(初期値 : false)
Результат string
    public function getContentsName($detail = false, $options = array())
    {
        $options = array_merge(array('home' => 'Home', 'default' => 'Default', 'error' => 'Error', 'underscore' => false), $options);
        $home = $options['home'];
        $default = $options['default'];
        $error = $options['error'];
        $underscore = $options['underscore'];
        $prefix = '';
        $plugin = '';
        $controller = '';
        $action = '';
        $pass = array();
        $url0 = '';
        $url1 = '';
        $url2 = '';
        $aryUrl = array();
        if (!empty($this->request->params['prefix'])) {
            $prefix = h($this->request->params['prefix']);
        }
        if (!empty($this->request->params['plugin'])) {
            $plugin = h($this->request->params['plugin']);
        }
        $controller = h($this->request->params['controller']);
        if ($prefix) {
            $action = str_replace($prefix . '_', '', h($this->request->params['action']));
        } else {
            $action = h($this->request->params['action']);
        }
        if (!empty($this->request->params['pass'])) {
            foreach ($this->request->params['pass'] as $key => $value) {
                $pass[$key] = h($value);
            }
        }
        $url = explode('/', h($this->request->url));
        if (@$this->request->params['Site']['alias']) {
            array_shift($url);
        }
        if (isset($url[0])) {
            $url0 = $url[0];
        }
        if (isset($url[1])) {
            $url1 = $url[1];
        }
        if (isset($url[2])) {
            $url2 = $url[2];
        }
        // 固定ページの場合
        if ($controller == 'pages' && $action == 'display') {
            if (strpos($pass[0], 'pages/') !== false) {
                $pageUrl = str_replace('pages/', '', $pass[0]);
            } else {
                if (empty($pass)) {
                    $pageUrl = h($this->request->url);
                } else {
                    $pageUrl = implode('/', $pass);
                }
            }
            $sitePrefix = $this->getSitePrefix();
            if ($sitePrefix) {
                $pageUrl = preg_replace('/^' . preg_quote($sitePrefix, '/') . '\\//', '', $pageUrl);
            }
            if (preg_match('/\\/$/', $pageUrl)) {
                $pageUrl .= 'index';
            }
            $pageUrl = preg_replace('/\\.html$/', '', $pageUrl);
            $pageUrl = preg_replace('/^\\//', '', $pageUrl);
            $aryUrl = explode('/', $pageUrl);
        } else {
            // プラグインルーティングの場合
            if (($url1 == '' && in_array($action, array('index', 'mobile_index', 'smartphone_index')) || $url1 == $action) && $url2 != $action && $plugin) {
                $prefix = '';
                $plugin = '';
                $controller = $url0;
            }
            if ($plugin) {
                $controller = $plugin . '_' . $controller;
            }
            if ($prefix) {
                $controller = $prefix . '_' . $controller;
            }
            if ($controller) {
                $aryUrl[] = $controller;
            }
            if ($action) {
                $aryUrl[] = $action;
            }
            if ($pass) {
                $aryUrl = array_merge($aryUrl, $pass);
            }
        }
        if ($this->_View->name == 'CakeError') {
            $contentsName = $error;
        } elseif (count($aryUrl) >= 2) {
            if (!$detail) {
                $contentsName = $aryUrl[0];
            } else {
                $contentsName = implode('_', $aryUrl);
            }
        } elseif (count($aryUrl) == 1 && $aryUrl[0] == 'index') {
            $contentsName = $home;
        } else {
            if (!$detail) {
                $contentsName = $default;
            } else {
                $contentsName = $aryUrl[0];
            }
        }
        if ($underscore) {
            $contentsName = Inflector::underscore($contentsName);
        } else {
            $contentsName = Inflector::camelize($contentsName);
        }
        return $contentsName;
    }