1

私がやろうとしているのは、この状況でルートが必要になるかどうかを判断することです。ユーザーがサイトに登録すると、確認メールが送信され、リンクをクリックしてアクティブ化コントローラーに送信されます。そこで、最初のパラメーターが数値で、2 番目のパラメーターが文字列であることを確認します。ユーザーは正常にアクティブ化されました。

これが私のコントローラー用のものです:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Activate extends CI_Controller { 

public function __construct()
{
    parent::__construct();
    $this->load->library('auth');
}

public function index()
{
    //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*/

    $x = 0;
    if(($param1 !== NULL)&&($param2 !== NULL))
    {

        //params not null yay..
        if((isset($param1))&&((trim($param1) !== '')||(!empty($param1))))
        {
            if(!is_numeric($param1))
            {
              $x++;
            }
        }
        if((isset($param2))&&((trim($param2) !== '')||(!empty($param2))))
        {
            if(!preg_match('/^[A-Za-z0-9]+$/', $param2))
            {
              $x++;
            }
        }


        if($x !== 0)
        {
           $bodyContent = $this->config->item('defaultTemplate') ."error_page";
        }
        else
        {
           $bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
        }

    }
    else
    {
        $bodyContent = "error_page";
    }

    /***********************************************************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['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
    $this->data['bodyType'] = $bodyType;
    $this->data['bodyContent'] = $bodyContent;
    $this->load->view($this->config->item('defaultTemplate') .'/usermanagement/index', $this->data);
}

}

/* End of file register.php */ 
/* Location: ./application/controllers/register.php */ 

私の URL は siteurl.com/activate/10000/7dfdao87fda8f7 のようになります

4

1 に答える 1

0

URLが次のようhttp://example.com/activate/account/12345/abcdeになる場合、ルートは必要ありません。

その場合はhttp://example.com/activate/12345/abcde、次のようなルートが必要になります。

$route["activate/(:num)/(:any)"] = "activate/account/$1/$2";

これは、アカウントをアクティブ化するために使用するactivateメソッドがコントローラーにあることを当然のこととしています。account

これが行うことは、最初の角かっこで囲まれた値 (数値) を$1取り、それを の場所に挿入し、次に角かっこで囲まれた 2 番目の値 (任意の文字) を取り、それを の代わりに挿入することです。$2

次に、次のコントローラー/メソッドを使用する必要があります。

class Activate extends CI_Controller {
    public function account ($var1, $var2) {
        // ...process vars etc
    }
}

index メソッドを使用する場合は、変数を渡してからルートで呼び出す必要があります。

class Activate extends CI_Controller {
    public function index ($var1, $var2) {
        // ...process vars etc
    }
}

$route["activate/(:num)/(:any)"] = "activate/index/$1/$2";

これは、これを に変更することで、 index メソッドactivate/$1/$2ではなく のメソッドを探すように指示しているためです。$1

于 2012-05-22T18:48:47.660 に答える