2011-11-22 213 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

唯一的变化是传记链接,如果你发现它进入生物/传记/小子,不知道的,而不是生物/小子,难怪这就是它应该去,因为它的索引功能。 –