1
votes

I am new to CodeIgniter and Ion Auth as well. All is well but when I am trying to delete user it doesn't delete any user by id.

I have added link for delete user as below in views/auth/index.php file, which lists all users.

<td><?php echo anchor("auth/edit_user/".$user->id, 'Edit') ;?> / <?php echo anchor("auth/delete_user/".$user->id, 'Delete') ;?></td>

I have created a page called delete_user.php and added delete_user($user->id) in the file. I am not sure I am doing any silly mistake.

Now when I click on delete link it takes me to the 404 which is obvious. So just wonder what I am missing? Do I need to add something in Controller? If yes than how can I write to delete the user and/or users?

BTW the MVC pattern is very confusing and sometime I feel it creates problem rather than make work easy.

Thanks a lot..

1
Your statement on the MVC pattern is fairly ambiguous. What kind of problems do you face while using it? The MVC pattern is fairly simple. Models are interface to the database, the Views are the presentation layer and the Controllers are interface between the two. All your business login will go in the Controllers. - Aniket
I found Model and Controller are confusing and one of them can be discontinued. In fact they (CI) also feel the same. ellislab.com/codeigniter/user-guide/overview/mvc.html - Code Lover
It's CI's view and if they discontinue one of those, then it means that it won't be a MVC. CI has a very warped concept for writing applications and that is one of the reasons I switched. Moreover, CI applications give you a lot of flexibility but that goes against the logic. - Aniket
That was my independent opinion regardless what they are thinking. I found MVC is very confusing and have to deal with many unwanted stuffs. I may wrong and may start to feel comfortable with MVC in later stage... - Code Lover

1 Answers

3
votes

From the looks of it, all you have done is create a link going to auth/delete_user and you most definitely do need to add something in the Controller!!

When you say you've "created a page called delete_user.php", is this a Controller you've created, or a View?

If you take a look inside the auth.php file in your Controllers you will see a function called edit_user($id). This is where the link auth/edit_user/ . $user->id goes to when you click it.

In order for the auth/delete_user/ . $user->id link to work, you will need to create a new function in the auth.php file called delete_user($id).

Ion Auth already has a Model function called delete_user($id) so as a bare minimum, in your newly created controller function, you can call $this->ion_auth->delete_user($id).

I would definitely recommend reading up on Codeigniter to gain a better understanding of the framework and the MVC pattern in general!!

I hope that helps you out anyway...