English 中文(简体)
URI 编码协调器的编码
原标题:URI Routing for codeigniter

我试图说明我应如何这样做。 The following controller is for a bio page for each wrestler. 这里就是一个例子。

http://kansasoutlawwrestling.com/bio/kid-wonder”rel=“nofollow” http://kansasoutlawwrestling.com/bio/kid-wonder

如果你注意到,现在有三个联系点: Biography, Wrestling, Appearances.

我有一个问题,即所有三个职能都应该在这一控制人员内部的不同?

如果答案是肯定的,该链接实际上是否正确?

<?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 */

EDIT:我确实关心的是像上述链接一样在生物页上的Im时的书目链接。

这里指我目前路线的美元[生物/(:任何)]=“生物/指数/1”;

最佳回答

在3个链接中,每个环节都有单独的控制器是最好的。

但是,如果你不希望,并且仍然希望连接<条码>/耳光,那么,在此,你需要将其全部保留在生物控制器内:

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/kid 可查阅bio/wrestling/kid

。 至bio/appearances/kid

问题回答

您目前拥有这一职位:

www.un.org/Depts/DGACM/index_spanish.htm 职能

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

www.un.org/Depts/DGACM/index_spanish.htm 链接

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

If you wanted to have the wrestling/kid-wonder and appearances/kid-wonder without the bio at the beginning of the url, you are going to need to create new controllers for wrestling and appearances.

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

   }
 }
}

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

   }
 }
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...