簡體   English   中英

CI路由問題不變

[英]CI Route Issue Not Getting Variable

我對此路線有疑問,不確定我的問題到底是什么。

我的頁面位於http://www.kansasoutlawwrestling.com/kowmanager/pmsystem/viewmessage/1 ,其中1是消息ID。

我設置了一條路線,看起來像

$route['pmsystem/viewmessage/(:num)'] = 'pmsystem/viewmessage/$1'; 

而且我仍然收到這樣的錯誤消息

A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Pmsystem::viewmessage()

Filename: controllers/pmsystem.php

Line Number: 76


// View A Message
function viewmessage($message_id)
{
    //Config Defaults Start
    $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
    $cssPageAddons = '';//If you have extra CSS for this view append it here
    $jsPageAddons = '<script src='.base_url().'../assets/js/cpanel/personalmessages.js></script><script src='.base_url().'assets/js/mylibs/jwysiwyg/jquery.wysiwyg.js></script>';//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*/

    // Checks to see if a session is active for user and shows corresponding view page
    if (!$this->loggedin->chkLoginStatus() === FALSE) 
    {
        if( ! $this->uri->segment(3))
        {
            redirect('error', 'refresh');
        }
    }
    else
    {
        redirect('login', 'refresh');
    }
    $bodyContent = 'viewpm';//which view file
    $bodyType = "full";//type of template                   

    /***********************************************************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->data['user_data'] = $this->users->getUserByUserId($this->session->userdata('user_id'));
    $this->data['users'] = $this->loggedin->getUserList();
    $this->data['personal_messages'] = array($this->pmmodel->getTotalMessages($this->session->userdata('user_id')), $this->pmmodel->getTotalUnreadMessages($this->session->userdata('user_id')), $this->pmmodel->getLast5Messages($this->session->userdata('user_id')));
    $this->data['messages'] = array($this->pmmodel->getInboxMessages($this->session->userdata('user_id')), $this->pmmodel->getSentMessages($this->session->userdata('user_id')));
    //$this->data['message_data'] = $this->pmmodel->getPmMessage($this->uri->segment(3));
    $this->load->view('cpanel/index', $this->data);
}

更新

 // Checks to see if a session is active for user and shows corresponding view page
    if (!$this->loggedin->chkLoginStatus() === FALSE) 
    {
        if (!is_numeric($this->uri->segment(3)))
        {
            $this->data['message_data'] = 'Invalid message id!';
        }
        else
        {
            $this->data['message_data'] = $this->pmmodel->getPmMessage($this->uri->segment(3));
        }
        $bodyContent = 'viewpm';//which view file
    }
    else
    {
        redirect('login', 'refresh');
    }

    $bodyType = "full";//type of template   

這條路線是不必要的-它不會改變任何東西。

$route['pmsystem/viewmessage/(:num)'] = 'pmsystem/viewmessage/$1'; 

您可以刪除該路線。 問題在這里:

function viewmessage($message_id) // no default value means it's required
{
    // your code
}

您的控制器方法從字面上接受用戶輸入作為參數(無論地址欄中的內容如何)。 您始終必須考慮CI控制器方法中不存在的那些必需參數。

function viewmessage($message_id = NULL)
{
    if ( ! $message_id) show_404();
    // your code
}

如果所需的$message_id不存在,這將使錯誤靜音並顯示404。 另外, $this->uri->segment(3)是不必要的,因為它的值$message_id相同。

當您確實需要404時,我強烈建議不要重定向到錯誤頁面,但這取決於您。 當重定向后地址丟失時,它肯定不會幫助用戶意識到他們的錯誤,並且這樣做會發送錯誤的HTTP標頭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM