I have a model register.php (under app/model/register.php)
<?PHP
// Load the [default] db group
$this->load->database();
// Get Input from init form, sanitize, plop into variables.
class Register extends Model{
function formModel(){
//load parent constructor
parent::Model();
}
function sanitizeInput(){
var $name = mysql_real_escape_string($_POST['fullname']);
var $email = mysql_real_escape_string($_POST['email']);
var $pass = mysql_real_escape_string($_POST['password']);
var $dySalt = mt_rand(20,100);
var $pass = hash('sha512',$dySalt.$pass);
}
// Set form variables into object; define db table
$registeredObject = new getSanitizeNewRegistrant();
$tbl = 'Fan';
function SendRequestForData(){
if{
$this->db->insert($tbl,$object);
// .. redirect()
echo "Sent";
}
else{
echo "Oops, could not register you";
}
}
}
?>
I’m loading this model into a controller registerUsers.php (under app/controller/registerUsers.php)
<?PHP
$this->load->model('register'),'', TRUE);
?>
I’m confused how I go about implementing this in a view from here?
The MVC framework works as follows:
Model interacts with the database:
Here is where you want to put all of your functions that do nothing more than insert and return data to/from the database.
Views are what the user sees:
Here is where you’ll have your html pages that make use of the data you got through your model
Controllers simply connect the two:
The controller preps data, uses the model to interact with the database, and loads the views for the user to see
If you had a function
registerUser()in your register model, you would do something like this to actually use it within a function in the controller:Here, the controller loads the register model, tries to save the username, email and password using the
registerUser()function within the model, and loads the correct view accordingly.Obviously you’ll want to clean
$_POSTdata and everything before writing it to the database. This should be done within the controller.