Welcome Guest, Not a member yet? Register   Sign In
Two views one controller
#1

Hey!

I just have one controller:
  • Students

And two views:
  • students_v //Show a list of all students
    form_students_v //the page that has a form to create a new student

All that i want is to make the Students controller handles all the methods. I dont want to create another controller called Form_studens.

So... How can i make the original Students take care of the two views? Is the best practice create a method inside the Students to load the form_students_v page? I should use a helper to load that?

Its so confusing to me...

Tks
Reply
#2

(This post was last modified: 08-24-2015, 09:44 PM by pdthinh.)

(08-24-2015, 05:16 PM)snape Wrote: Hey!

I just have one controller:




  • Students

And two views:




  • students_v    //Show a list of all students
    form_students_v //the page that has a form to create a new student

All that i want is to make the Students controller handles all the methods. I dont want to create another controller called Form_studens.

So... How can i make the original Students take care of the two views? Is the best practice create a method inside the Students to load the form_students_v page? I should use a helper to load that?

Its so confusing to me...

Tks
One controller can have as many methods as you want. Maybe I show a skeleton:


PHP Code:
class Students extends CI_Controller

{
public function 
__construct()
{
// init student
}

// method for list all students (default)
public function index()
{
// get all students and store in $data
// load view file
// e.g: $this->load->view('students_v', $data);
}

// method for edit a student
public function edit($id)
{
// get the student by $id and store in $data
// load view file
// e.g: $this->load->view('form_students_v', $data);
}

// Students 


You can read more http://www.codeigniter.com/user_guide/ge...ml#methods
Reply
#3

Thks, man.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB