2011-11-22 3 views
0

나는 이것을 어떻게해야하는지 알아 내려고하고있다. 다음 컨트롤러는 각 레슬러의 바이오 페이지 용 컨트롤러입니다. 여기에 예제가 있습니다.URI codeigniter에 대한 라우팅

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";

기능

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

당신이에서 바이오없이 wrestling/kid-wonderappearances/kid-wonder을하고 싶었다면 링크

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

:

답변

1

3 개의 링크 각각에 별도의 컨트롤러가있는 것이 가장 좋습니다. 당신이 원하지 않는, 여전히 링크 /appearances/whatever 원하는 경우

그러나, 여기 당신이 바이오 컨트롤러 내에서 모든 것을 계속해야 라우팅 :

UPDATE -이 여전히 나쁜 방법이지만, 해야 할 것.

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/kidbio/wrestling/kid

appearances/kidbio/appearances/kid

+0

하지만 약력 링크는 어떨까요? 그것은 바이오/전기/아이 - 궁금에 가고 싶어합니다.그것은 그 인덱스 함수로 가야합니다. –

+0

당신이 이미 가지고있는 것을 추가하면 ('$ route [ 'bio/(: any)'] = "bio/index/$ 1"; – Shomz

+0

다른 두 개를 아래에 두는 것이 중요한 이유는 무엇입니까? 하지만 그건 btw 작동하지 않았다. –

1

현재이 설정을 가지고 URL의 시작, 당신은 가고있다. 레슬링과 외모를위한 새로운 컨트롤러를 만들어야합니다.

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

당신이 바이오/전기 /로 이동이있을 때는 단 하나의 변화는 전기 링크입니다로 이동이 이후에 진행해야한다 무엇을하는 대신 바이오/아이 - 경이의 아이-궁금해 그것의 색인 기능. –

관련 문제