Basically I have two controllers using CodeIgniter for a simple blog for a project at school.
One is Home which is the login page. The other is Member for when they are signed in. in this member controller I am creating functions for add_post(), view_users_posts(), etc.
Member.php
class Member extends CI_Controller{
function __construct(){
parent::__construct();
$is_logged_in = $this->session->userdata('is_logged_in');
if (!isset($is_logged_in) || $is_logged_in !== true) {
redirect('home');
}
}
public function index() {
$this->load->library('pagination');
$config['base_url'] = base_url() . 'index.php/member/index/';
$config['total_rows'] = $this->db->get('posts')->num_rows();
$config['per_page'] = 5;
$config['num_links'] = 20;
$this->pagination->initialize($config);
$data['posts'] = $this->posts_model->get_all_posts($config['per_page'], $this->uri->segment(3));
$this->load->view('member_view', $data);
}
public function add_post() {
$this->load->view('add_post_view');
}
My member view has a nav menu with links to these functions like so:
member_view.php
<li><a href="member">Home</a></li>
<li><a href="member/add_post">Add Post</a></li>
<li><a href="member/view_users_posts">My Posts</a></li>
<li><a href="member/reset_pass">Reset Password</a></li>
<li><a href="member/logout">Logout</a></li>
I haven’t finished them as I am having trouble knowing what to code. Basically if the user clicks Add Post should it refer to the function add_post in the controller which will load a view called add_post? Or should it direct to a new controller called Add_post that will load the view?
My reason is if I click add post it takes me to member/add_post but when I click back home I get member/member then add post again I get member/member/add_post.
I hope this makes sense, I am at a total loss. Thanks for any help!
you need to use
base url.Suppsoe your base url is (in the config), http://www.example.com/
then your code will be
Do the same for other items.
Note: Remember slash in the config file. otherwise include it in
base_url('/member/add_post')Reference