2012-02-06 5 views
0

나는 내 경로와 컨트롤러를 처리하는 방법을 알아 내려고하고 있습니다.여러 변수 컨트롤러 후 URL

사용자가 내 사이트에 등록하면 계정을 확인하기 위해 비밀번호를 묻는 활성화 컨트롤러에 대한 링크가 포함 된 이메일이 전송됩니다. 그러나 내 컨트롤러에 if 문을 추가하여 URL의 활성화 마지막에 두 개의 매개 변수가 있는지 확인한 다음 오류 페이지가 표시되지 않는지 확인합니다. 또한 첫 번째 매개 변수가 숫자인지 확인해야합니다.

어떤 이유로 나는 올바르게 설정되어 있고 무엇이 확실하지 않습니다.

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

class Activate extends CI_Controller 
{ 

public function __construct() 
{ 
    parent::__construct(); 
    $this->load->library('kow_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 = '<script src="http://www.kansasoutlawwrestling.com/kowmanager/assets/js/activatevalidate.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*/ 

    if (is_numeric($this->uri->segment(3)) OR $this->uri->segment(4) == '') 
    { 
     $bodyContent = "error_page"; 
    } 
    else 
    { 
     $bodyContent = "activate_form";//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->load->view('usermanagement/index', $this->data); 
} 

function activate_submit() 
{   
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric'); 

    $user_id   = $this->uri->segment(3); 
    $registration_key = $this->uri->segment(4); 

    if (($registration_key == '') OR ($user_id == '')) 
    { 
     echo json_encode(array('error' => 'yes', 'message' => 'URL was not complete!')); 
    } 
    else 
    { 
     if (!$this->form_validation->run()) 
     { 
      echo json_encode(array('error' => 'yes', 'message' => 'There was a problem submitting the form! Please refresh the window and try again!'));  
     } 
     else 
     {       
      if ($this->kow_auth->activate_user($user_id, $registration_key, $this->input->post('password'))) 
      { 
       echo json_encode(array('sucess' => 'yes', 'message' => 'Your account has been successfully activated!')); 
      } 
      else 
      {               
       echo json_encode(array('error' => 'yes', 'message' => 'The activation code you entered is incorrect or expired!')); 
      } 
     } 
    } 


} 

} 

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

오류 컨트롤러

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

class Error extends CI_Controller 
{ 

public function __construct() 
{ 
    parent::__construct();   
} 

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

    $bodyContent = "error_page";//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->load->view('usermanagement/index', $this->data); 
} 

} 

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

모든 추가 아이디어 :

는 여기에 내가

$route['activate/:num/:any'] = "activate"; 

컨트롤러 경로에 사용되는 무엇인가?

수정 아래의 두 가지 대답으로도 여전히 동일한 오류 메시지가 표시됩니다. 에

http://www.kansasoutlawwrestling.com/kowmanager/activate/

답변

1

저는 My_Mark에 동의 할 것입니다. 그의 답변은 처음에 요청한 내용을 기반으로합니다. 그래서 우리는 그의 초기 응답을 기본으로 삼을 것입니다. 당신의 문제는 당신의 if-else에 있습니다.

당신은 내가 당신이 컨트롤러가 어디를 설정 한 경우보다 같은

또한
public function index($param1 = NULL, $param2 = NULL) 

이이 컨트롤러의 인덱스 기능을위한주의보고 변경할 것입니다 그러나

public function index($param1, $param2) 

해야합니다 예를 들어 activate 함수와 같은 함수를 기반으로 여러 뷰가 실행되고 있어야합니다. 그런 다음 "index ("를 "activate (". )로 바꿔야합니다. 두 번째로 누군가가 컨트롤러에 착륙했거나 404 오류가 발생하면 매개 변수가 충족되지 않은 경우 사용자의 말을 살펴보십시오. 이것이 제가 위의 방식으로 변경 한 이유입니다.이 방식으로 함수가 설정되지 않은 매개 변수를 찾고 있지 않으며 오류가 설정되지 않을 것입니다. 따라서 우리는 NULL로 기본값을 설정합니다.

So 내 솔루션은 뭔가를 할 것입니다 ..

$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(/*whatever your constraint for $param2 (!preg_match()) or something*/) 
     { 
      $x++; 
     } 
    } 


    if($x !== 0) 
    { 
     $bodyContent = "error_page"; 
    } 
    else 
    { 
     $bodyContent = "activate_form"; 
    } 

} 
5

변경은 경로 :

public function index($param1, $param2) 

당신에게 :

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

이이처럼 활성화 컨트롤러의 색인 기능으로 두 개의 매개 변수를 전달 할 수 있습니다 그러면 다음 작업을 수행 할 수 있습니다.

if (is_numeric($param1) OR $param2 == '') 
{ 
    $bodyContent = "error_page"; 
} 
else 
{ 
    $bodyContent = "activate_form"; 
} 

호프가 도움이됩니다.

+0

+1이게 내가 말하려고했던 것입니다 ... – Alex

+0

이 URL로 이동하면 문제가됩니다. http://www.kansasoutlawwrestling.com/kowmanager/activate/ 바로 404 페이지를 보여 주어야합니다. 그리고 만약 내가 이것을 시험처럼하면 http://www.kansasoutlawwrestling.com/kowmanager/activate/jdahkjf/271cce33ab11ced5fd10aeca41323a3c 그것은 이상한 메시지로 나타납니다. –

+0

기본 404 오버라이드 컨트롤러 인 오류 컨트롤러를 추가했지만 동일한 템플릿 페이지 코드를 추가했습니다. 왜 그것이 그 오류를주는 지 잘 모르겠다. –