0

在下面的 If.. else 语句中,我想先看看是否有第四个面包屑(URI 数组 4),然后看看它是否是一个数字。

但两者总是返回真、数字、字母或空..

谁能告诉我为什么?

// checks the third breadcrumb contained within the breadcrumbs class to see
// if it is an article. Then uses a recursive function to search the first
// and second breadcrumbs to see if they exist within their respective menu
// arrays. finally, if that validates, then the fourth breadcrumb is checked
// to see if it exists (not empty) AND if it is a number.
else 
if (($this->breadcrumbs->getCrumb(3)=='article' && 
     $array_helper->recValueReturn($this->breadcrumbs->getCrumb(2),
     $this->getNavTwo()) && 
     $array_helper->recValueReturn($this->breadcrumbs->getCrumb(1),
     $this->getNavOne())) || ($this->breadcrumbs->getCrumb(4)) && 
     is_numeric($this->breadcrumbs->getCrumb(4))) {
...

以下始终验证为 False:

else
if (($this->breadcrumbs->getCrumb(3)=='article'&&
     $array_helper->recValueReturn($this->breadcrumbs->getCrumb(2),
     $this->getNavTwo()) &&
     $array_helper->recValueReturn($this->breadcrumbs->getCrumb(1),
     $this->getNavOne())) &&
     (array_key_exists($this->breadcrumbs->getCrumb(4),
      $this->breadcrumbs->getCrumbs())&&
      is_numeric($this->breadcrumbs->getCrumb(4)))) {
...
4

1 回答 1

1

供将来参考,以及其他阅读本文的人。

该问题已在 BreadCrumbs 类本身中得到解决。

以前,面包屑有一个私有数组,其中包含分解的 URI 值。我使用以下方法检索了一个 url 索引:

public function getCrumb($x) { return $this->breadcrumbs[$x] }

但是如果我直接修改这个getter以包含一个isset:

public function getCrumb($x) {
    if (isset($this->breadcrumbs[$x])) {
        return $this->breadcrumbs[$x];
    } else {
            return null;
    }
}

然后在OP中使用第一个else..if ..问题解决了。有用。

于 2013-01-23T06:25:56.617 回答