I have something I wrote in codeigniter using the mvc structure that I would like to add to a website I am building in EE. I’m just not sure of the best approach. The site is in EE 2.4.
Here is what I’m trying to do. On the EE site, I have a member registration form using the Solspace User module. This form however, should only be accessed by our current customers. The CI app has a form that allows the user to input a sales order number and two other identifiable values that we check against a database table to make sure it exists. If so, the information is passed into a session and the user is moved forward to a registration form. I am having trouble adding this to my EE sight though. I am assuming I need to create an EE module but have never built one before so I’m having a little trouble translating my model and controller from CI. Any help would be very much appreciated.
First I would go through this if you have not already: http://ellislab.com/expressionengine/user-guide/development/module_tutorial.html
Here are some docs that will be helpful in creating front-end forms in your module: http://ellislab.com/expressionengine/user-guide/development/reference/functions.html#form-declaration-data-array http://ellislab.com/expressionengine/user-guide/development/reference/functions.html#fetch-action-id-class-str-method-str
Here is a PHP class that wraps the form functions above: https://gist.github.com/2036924
As you move forward with the module I would recommend posting more specific questions as you run into them.
Just to spread a little more light on this. I am posting my model and controller files:
Model
class M_verify extends CI_Model
{
function verify($co, $m_height, $m_width)
{
$this -> db -> select('id, co, m_height, m_width');
$this -> db -> from('verify');
$this -> db -> where('co = ' . "'" . $co . "'");
$this -> db -> where('m_height = ' . "'" . $m_height . "'");
$this -> db -> where('m_width = ' . "'" . $m_width . "'");
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
}Controller 1
class Verify extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->helper(array('form', 'url'));
$this->load->view('v_verify');
}
}Controller 2
class Credentials extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('m_verify','',TRUE);
}
function index()
{
//This method will have the credentials validation
$this->load->library('form_validation');
$this->form_validation->set_rules('co', '', 'trim|required|xss_clean|max_length[7]|callback_check_database');
$this->form_validation->set_rules('m_height', '', 'trim|required|xss_clean|callback_check_database');
$this->form_validation->set_rules('m_width', '', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->load->view('v_verify');
}
else
{
//Go to private area
redirect('sign_up', 'refresh');
}
}
function check_database()
{
//Field validation succeeded. Validate against database
$co = $this->input->post('co');
$m_height = $this->input->post('m_height');
$m_width = $this->input->post('m_width');
//query the database
$result = $this->m_verify->verify($co, $m_height, $m_width);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->id,
'co' => $row->co,
'm_height' => $row->m_height,
'm_width' => $row->m_width
);
$this->session->set_userdata('verified', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid');
return false;
}
}
}Controller 3
session_start(); //we need to call PHP's session object to access it through CI
class Sign_up extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
if($this->session->userdata('verified'))
{
$session_data = $this->session->userdata('verified');
$data['co'] = $session_data['co'];
$data['m_height'] = $session_data['m_height'];
$data['m_width'] = $session_data['m_width'];
$this->load->view('v_sign_up' , $data);
}
else
{
//If no session, redirect to login page
redirect('credentials', 'refresh');
}
}
function cancel()
{
$this->session->unset_userdata('verified');
session_destroy();
redirect('credentials', 'refresh');
}
}Don’t know if this would help with answers. But, worth a shot. Thanks!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.