codeigniter 的 URI 路由

发布于 2024-12-17 09:01:56 字数 4735 浏览 0 评论 0原文

我正在尝试弄清楚我应该如何做到这一点。以下控制器用于每个摔跤手的个人简介页面。这是一个例子。

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

I'm trying to figure out how I should do this. The following controller is for a bio page for each wrestler. Here's an example.

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

Now if you notice there's three links Biography, Wrestling, Appearances.

One question I have is should all three be different functions inside this controller?

If the answer is yes are the links actually correct on the page link?

<?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: I'm really concerned with the biography page link when I'm on the bio page like the link above.

Here's what I have currently for my route: $route['bio/(:any)'] = "bio/index/$1";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空袭的梦i 2024-12-24 09:01:57

最好为 3 个链路中的每一个链路配备单独的控制器。

但是,如果您不想,并且仍然想要链接 /appearances/whatever,这里是您需要将其全部保留在 Bio 控制器内的路由:

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/kid 转到 bio/index/kid

摔跤/孩子转到bio/摔跤/孩子

appearances/kid 转到 bio/appearances/kid

It would be the best to have separate controllers for each of the 3 links.

But if you don't want to, and still want the links /appearances/whatever, here's the routing you need to keep it all within the Bio controller:

UPDATE - this is still a bad approach, but it should do.

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

UPDATE 2: you got me confused, but the first solution HAS to work, even the order doesn't matter:

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

bio/kid goes to bio/index/kid

wrestling/kid goes to bio/wrestling/kid

appearances/kid goes to bio/appearances/kid

泪痕残 2024-12-24 09:01:57

您当前拥有以下设置:

功能

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

链接

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

如果您想拥有摔跤/kid-wonder外观/kid-奇怪 如果网址开头没有简介,您将需要为摔跤和外观创建新的控制器。

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

   }
 }
}

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

   }
 }
}

You currently have this setup:

The functions

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

The links

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){

   }
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文