2011-11-21 16 views
0

我還有一個問題的一天。我正在努力使自己的傳記頁面完全可以爲我自定義的CMS項目進行自定義。如果你在視圖中注意到我有3個用於引用,盟友,對手的h2標籤。我想要做的是將h3放入我的db中,然後讓它爲每一個做一個foreach循環,所以我在想如何我必須存儲與頁面標題一起使用的函數如果它在頁面上不活動,它就不必運行它我知道這可以很容易地完成,但是爲了完成這個工作,我需要做的事情太多了,請記住,根據哪一個第頁你在生物會影響其標題將可頁面的標題和功能及其標題

至於現在這裏是我的控制器:

$activeTemplate = $this->sitemodel->getTemplate(); 
    $footerLinks = $this->sitemodel->getFooterNav(); 
    $bodyContent = "bio";//which view file 
    $bodyType = "main";//type of template 
    $this->data['activeTemplate'] = $activeTemplate; 
    $this->data['footerLinks']= $footerLinks; 
    $this->load->model('biomodel'); 
    if($character !== "jfkdlsjl") 
    { 
     if((!empty($character))||(!isset($character))||(trim($character) !== '')||($character !== NULL)) 
     { 
      $bioArray = $this->biomodel->getCharacterBio($character); 
      if ($bioArray == "empty") 
      { 
       $this->data['bioArray']= array(); 
      } 
      else 
      { 
       if (($bioArray[0]->characters_statuses_id == 2)||($bioArray[0]->characters_statuses_id == 3)||($bioArray[0]->characters_statuses_id == 5)) 
       { 
        $this->data['bioArray']= array(); 
       } 
       else 
       { 
        $this->data['bioArray']= $bioArray; 
        $bioPagesArray = $this->biomodel->getBioPages(); 
        $alliesArray = $this->biomodel->getCharacterAllies($bioArray[0]->id); 
        $rivalsArray = $this->biomodel->getCharacterRivals($bioArray[0]->id); 
        $quotesArray = $this->biomodel->getCharacterQuotes($bioArray[0]->id); 
        $this->data['bioPagesArray']= $bioPagesArray; 
        $this->data['alliesArray']= $alliesArray; 
        $this->data['rivalsArray']= $rivalsArray; 
        $this->data['quotesArray']= $quotesArray; 
       } 
      } 
     } 
    } 

這是我的觀點:

echo "<h2>Quotes</h2>"; 
    if (!empty($quotesArray)) 
    { 
     echo "<ul>"; 
     for($x = 0; $x <= (count($quotesArray)-1); $x++) 
     { 
      echo "<li>".stripslashes($quotesArray[$x]->quote)."</li>"; 
     } 
     echo "</ul>"; 
    } 
    echo "<h2>Allies</h2>"; 
    if (!empty($alliesArray)) 
    { 
     echo "<ul>"; 
     foreach ($alliesArray as $row) 
     { 
      echo "<li>".stripslashes($row)."</li>"; 
     } 
     echo "</ul>"; 
    } 
    echo "<h2>Rivals</h2>"; 
    if (!empty($rivalsArray)) 
    { 
     echo "<ul>"; 
     foreach ($rivalsArray as $row) 
     { 
      echo "<li>".stripslashes($row)."</li>"; 
     } 
     echo "</ul>"; 
    } 

回答

1

我不知道你對存儲函數的意思,也不知道你不想運行哪個函數。

假設我們在你的控制器

$alliesArray = $this->biomodel->getCharacterAllies($bioArray[0]->id); 
$rivalsArray = $this->biomodel->getCharacterRivals($bioArray[0]->id); 
$quotesArray = $this->biomodel->getCharacterQuotes($bioArray[0]->id); 

與上次else聲明的工作......你「不想跑」的功能是foreach循環視圖陣列上,只是處理您的看法中的邏輯:

if(($this->uri->segment(n)=='pageIwantQuotesOn') && (!empty($quotesArray)){ 
    echo "<h2>Quotes</h2>"; 
    echo "<ul>"; 
    for($x = 0; $x <= (count($quotesArray)-1); $x++) 
    { 
     echo "<li>".stripslashes($quotesArray[$x]->quote)."</li>"; 
    } 
    echo "</ul>"; 
} 
... 
相關問題