Welcome Guest, Not a member yet? Register   Sign In
Putting everything together
#1

[eluser]Lobosque[/eluser]
Hello CI community.
I'm trying to learn how to use CI and its my first time with MVC.
I have a simple question:
Lets say I have a authentication control with functions like login, register, and logout.
so I can login like www.example.com/authentication/login
Also, I have a control that take care of some data manipulation. The control name is data and it has two functions: list_items and add_item. So i can list my item trough www.example.com/data/list_items.
O.K, now comes my problem: How to put everything together?
In my index page, I want a login form in the right column, I want to list all items in the main column and I also want the little add_item form in the left column.
I could create a control named authentication_data and a function inside it named list_items_add_items_login. But of course that this is not the right solution.
Can someone explain me how is the best way to do it?
I hope i ilustrated well what is my doubt.
Thanks!
#2

[eluser]rdjs[/eluser]
If you are just starting out I would probably use one of the auth libraries to begin with, this may simplify things a bit.
#3

[eluser]Lobosque[/eluser]
rdjs Thanks for your reply.
I tried DX_auth and I learned a lot with it.
But I still confused about using 2 or more "things" together... Like the login of DX_auth and the list_items function (of my previous example).
#4

[eluser]rdjs[/eluser]
In your controller you do a check to make sure the person is logged in then you an do whatever you want. Although I have not used DX Auth it looks like this function is called is_logged_in() so...

Code:
function index()
{
     if(is_logged_in() == true)
     {
         // now we know the person is logged in we can...
        
         // fetch items from db
         $list_items = $this->items_model->get_data();

         // now $list_items contains the list data we can send it through to the view
         $this->load->view('list_view', $list_items);
     }
}




Theme © iAndrew 2016 - Forum software by © MyBB