Saturday 12 January 2019

php - CodeIgniter How to pass a variable from view to the controller

I'm currently working with Codeigniter. I'm trying to create a registration page.
The registration is in the view file. After fill the form for the registration, I would like to send the user's information to the controller. And after I want it to check if the information are valid (username are not already use.. valid email adresse and so on). If it's true so send the same information to the Model which add to the database. If it's false so load view registration page. I found a lot of topic talking about how to send variable from controller to view (Adding Dynamic Data to the View on CodeIgniter website) or controller to model but didn't find anything helpful about view->controller. Here's is what I want to do:



    VIEW                         CONTROLER
_______________ ______________________
|REGISTRATION:| -----------> |Check valid argument|
--------------- ----------------------
/|\ | |

|___________________| If it's valid information
(if no valid) |
|
\ /
MODEL
____________________________
|Add information to database|
-----------------------------



This is my form:



create a new account

























And here's my controller file




class Add_db extends CI_Controller
{

function __construct()
{
parent:: __construct();
$this->load->database();
}

function index()
{
//check if the password does match
//check before if the username is not already user

//open the model function which add to the database :)
}
}


I don't know if it's better to check the user's information in the model. Because I know that the model handle the database and the query.
Otherwise the controller handle calcul part so maybe the controller is more suitable for this task.
But doesn't matter. Is it possible to send information like view---->controller ?
Or have I to find another way for check information ?
Like controller -> view -> model ?




Thanks

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...