2012-05-22 82 views
1

我想要做的是找出如果我需要一個路線來處理這種情況。在用戶爲我的網站註冊後,他們會收到一封驗證郵件,在郵件中他們點擊一個鏈接併發送給激活控制器,在此驗證第一個參數是數字,第二個參數是一個字符串,然後如果它們與記錄匹配數據庫然後用戶被成功激活。激活路由和控制器

這裏就是我有我的控制器:

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

我的網址看起來像siteurl.com/activate/10000/7dfdao87fda8f7

+0

那麼,呃......網址是什麼? –

回答

0

如果您的網址將是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

的地方

然後需要使用下面的控制器/方法:

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

,如果你使用索引方法,你需要的變量傳遞給它,然後把它在路線:

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

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

這是因爲通過將其更改爲activate/$1/$2告訴它尋找$1中的方法,而不是索引方法。

+0

的帖子已更新,謝謝迄今爲止的回覆 –

+0

在這種情況下,我的回答很好,使用第二個選項 –

+0

我稍微改變了它,使路線更容易 –