Rutas de activación y controlador

What I'm trying to do is figure out IF I am going to need a route for this situation. After the user registers for my site they are sent a verification email in which they click a link and sent to the activate controller where it verifies that the first parameter is numeric and the second is a string and then if they match together with a record in the db then the user was successfully activated.

Here's what I have for my controller:

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

My urls look like siteurl.com/activate/10000/7dfdao87fda8f7

preguntado el 22 de mayo de 12 a las 19:05

so, erm... what will the URL be? -

1 Respuestas

if your URL will be http://example.com/activate/account/12345/abcde then you won't need a route.

si va a ser http://example.com/activate/12345/abcde then you will need a route like so:

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

that is taking for granted that the activate controller has a method called account which you use to activate accounts.

what this does is takes the first bracketed value (which is a number) and inserts it into the place of $1, then takes the second bracketed value (which is any character) and inserts it in the place of $2

you then need to use the following controller / method:

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

if you use the index method, you'd need to pass the variables to it and then call it in the route :

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

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

this is because by changing it to activate/$1/$2you are telling it to look for the method in $1, not the index method.

contestado el 22 de mayo de 12 a las 22:05

in that case, my answer is fine, use the second option - andres willis

I changed it slightly to make the route easier - andres willis

I did this and for some reason I'm getting a 404 page not found and not sure why. - jeff davidson

does your controller have an 'account' method? - andres willis

I changed it to this because it doesn't have an account function because I use the index function and still get the same error. $route["activate/(:num)/(:any)"] = "activate/$1/$2"; - jeff davidson

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.