2011-11-22 170 views
0

我想弄清楚我應該如何做到這一點。以下控制器用於每個摔跤手的生物頁面。這是一個例子。codeigniter URI路由

http://kansasoutlawwrestling.com/bio/kid-wonder

現在,如果你發現有三個環節傳記,摔跤,外觀。

我有一個問題應該是這三個控制器內部的不同功能?

如果答案是肯定的,鏈接實際上在頁面鏈接上是否正確?

<?php 
if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Bio extends CI_Controller 
{ 

function index($character = "jfkdlsjl") 
{ 

    //Config Defaults Start 
    $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg 
    $cssPageAddons = '';//If you have extra CSS for this view append it here 
    $jsPageAddons = '';//If you have extra JS for this view append it here 
    $metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's 
    $siteTitle = '';//alter only if you need something other than the default for this view. 
    //Config Defaults Start 


    //examples of how to use the message box system (css not included). 
    //$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...'); 

    /**********************************************************Your Coding Logic Here, Start*/ 


    $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; 
       } 
      } 
     } 
    } 

    /***********************************************************Your Coding Logic Here, End*/ 

    //Double checks if any default variables have been changed, Start. 
    //If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing. 
    if(count($msgBoxMsgs) !== 0) 
    { 
     $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs)); 
    } 
    else 
    { 
     $msgBoxes = array('display' => 'none'); 
    } 

    if($siteTitle == '') 
    { 
     $siteTitle = $this->metatags->SiteTitle(); //reads 
    } 

    //Double checks if any default variables have been changed, End. 

    $this->data['msgBoxes'] = $msgBoxes; 
    $this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view. 
    $this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view. 
    $this->data['metaAddons'] = $metaAddons;//if there is any addictional meta data to add from the above variable this will send it to the view. 
    $this->data['pageMetaTags'] = $this->metatags->MetaTags();//defaults can be changed via models/metatags.php 
    $this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php 
    $this->data['bodyType'] = $bodyType; 
    $this->data['bodyContent'] = $bodyContent; 
    $this->load->view($activeTemplate[0]->short_name.'/index', $this->data); 

} 
} 

/* End of file bio.php */ 
/* Location: ./application/controllers/bio.php */ 

編輯:我真的很擔心傳記頁鏈接,當我在上面的鏈接的生物頁面。這是我目前的路線:$ route ['bio /(:any)'] =「bio/index/$ 1」;

回答

1

這將是最好的3個鏈接的每一個單獨的控制器。

但是,如果你不想,但還是要鏈接/appearances/whatever,這裏的路由,你需要保持它所有的生物控制器內:

更新 - 這仍是一個不錯的辦法,但它應該做。

if ($this->uri->segment(1) == 'bio') { 
    $route['bio/(:any)'] = "bio/index/$1"; 
} else { 
    $route['wrestling/(:any)'] = "bio/wrestling/$1"; 
    $route['appearances/(:any)'] = "bio/appearances/$1"; 
} 

更新2:你讓我困惑,但第一個解決方案的工作,連順序並不重要:

$route['bio/(:any)'] = "bio/index/$1"; 
$route['wrestling/(:any)'] = "bio/wrestling/$1"; 
$route['appearances/(:any)'] = "bio/appearances/$1"; 

bio/kidbio/index/kid

wrestling/kid轉至bio/wrestling/kid

appearances/kidbio/appearances/kid

+0

但傳記鏈接雖然如此。這是想去生物/傳記/奇蹟。它應該去那個索引函數。 –

+0

添加你已經擁有的那個('$ route ['bio /(:any)'] =「bio/index/$ 1」;'),這兩者應該這樣做。 – Shomz

+0

爲什麼將它放在其他兩個之下很重要?但是這並不是順便說一句。 –

1

您目前有這樣的設置:

功能

function index($wrestlerName = null){ } 
function wrestling($wrestlerName = null){ } 
function appearances($wrestlerName = null){ } 

的聯繫

bio/kid-wonder 
bio/wrestling/kid-wonder 
bio/appearances/kid-wonder 

如果你想有wrestling/kid-wonderappearances/kid-wonder而不在生物網址的開頭,你要走了需要爲摔跤和出場創造新的控制器。

class wrestler extends CI_Controller { 
function index($wrestlerId = NULL){ 
    if($wrestlerId != NULL){ 

    } 
} 
} 

class appearances extends CI_Controller { 
function index($wrestlerId = NULL){ 
    if($wrestlerId != NULL){ 

    } 
} 
} 
+0

唯一的變化是傳記鏈接,如果你發現它進入生物/傳記/小子,不知道的,而不是生物/小子,難怪這就是它應該去,因爲它的索引功能。 –