Reputation: 113
iam back with another question to do with mvc and codeigniter. just getting a bit confused with the concept of MVC. First of all i have a button. i want it to reference another page. how i was going to access the next "view" or page was from this view was with a simple href="" inside a button like below.
href="<?php echo base_url();?>index.php/user/admin"
but this is a call to a method in my controller, which redirects to admin page. from what ive read this is bad practice as you cant call a controller method from a view. fair enough. but how do i actually link to the next page then? cheers
Upvotes: 1
Views: 10698
Reputation: 19882
You should do it like this
<a href="<?php echo site_url('user/admin')?>">
And here is the controller method of user class to which you are going
function admin(){
$this->load->view('mypage');
}
Make sure you allow it to access. I mean there is no check in constructor to redirect somewhere else.
Upvotes: 1
Reputation: 7475
You always interact with the controller directly from the view. Calling href="<?php echo base_url();?>index.php/user/admin"
means you interacting with the admin function
of user controller
and this is perfectly fine. No worries.
Upvotes: 3