MVC方法,这仍然是正确的方式吗?

About a week ago i started experimenting with CodeIngiter, because i want to learn OOP. I thought i was on the right track, but now i begin to doubt that. The reason is, i have a controller for Members, which is becoming quite a large file. This is because i want my urls to be like members/login , members/register etc.

Here is my controller:

<?php
class Members extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('users');
    }
    public function index()
    {
    }
    public function register()
    {
        $this->load->helper(array(
            'form',
            'recaptcha'
        ));
        $this->load->library('form_validation');
        $data['title']       = "Register a free account - Become an Author";
        $data['titlesucces'] = "Thanks for registering";
        $this->form_validation->set_rules('fname', 'First name', 'required');
        $this->form_validation->set_rules('lname', 'Last name', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('passwordconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Emailaddress', 'required|is_unique[users.email]|valid_email');
        $this->form_validation->set_rules('recaptcha_challenge_field', 'Captcha', 'required|recaptcha_matches');
        if (!$this->form_validation->run()) {
            $this->load->view('header', $data);
            $this->load->view('register', $data);
        } else {
            $this->users->register_new_member();
            $this->load->view('register_succes', $data);
        }
    }
    public function login()
    {
        $data['title'] = "Login";
        $data['fail']  = "";
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('email', 'Emailaddres', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        if (!$this->form_validation->run()) {
            $this->load->view('login', $data);
        } else {
            if ($this->users->do_login($this->input->post('email'), $this->input->post('password'))) {
                $this->load->view('login', $data);
            } else {
                $data['fail'] = "Emailaddress or password is incorrect";
                $this->load->view('login', $data);
            }
        }
    }
    public function logout()
    {
        $this->session->sess_destroy();
        redirect('/members/login/', 'refresh');
    }
    public function addarticle()
    {
        if ($this->users->logged_in()) {
            $this->load->helper('form');
            $this->load->library('form_validation');
            $this->form_validation->set_rules('title', 'Title', 'required|max_length[200]|min_length[10]');
            $this->form_validation->set_rules('intro', 'Intro', 'required|min_length[40]|max_length[50]');
            $this->form_validation->set_rules('cat', 'Category', 'required');
            $this->form_validation->set_rules('body', 'Article', 'required|min_length[3000]|link_check');

            $this->load->model('categories');
            $data['title'] = "Add a new article";
            $data['cats']  = $this->categories->get_all_categories();
            if (!$this->form_validation->run()) {
                $this->load->view('addarticle', $data);
            } else {
                $this->load->model('articles');
                $this->articles->add_new_article();
                $this->load->view('welcome');
            }
        } else {
            redirect('/members/login/', 'refresh');
        }
    }

}
?>

As you can see its quite a big file already, but it will only get bigger. Now my question to you guys is: is this still the right MVC way or am i doing something wrong?

Thanks!

You are doing completelly right things, and this file isn't big anough yet, and I doubt it will be. I've programmed on CodeIgniter - great and light-weight FW, and there is a cool MVC model/pattern workarounds. So just keep going.

Another thing while Your file/controller didn't achive 1000-1500 lines of code do not bother Your-self with this question.

The MVC is not actually what Your controller contains, rather than whole bunch of things Models(DB Queries, Herlper Functions), Views(Templates/GUI) and Controller(Logic) - keep that in mind and do not worry about anything at this point.

I have created a few critical high availability systems in CodeIgniter, and found it wonderfully powerful and greatly flexible for my particular projects. It does not have the large baggage that comes with other "enterprise" frameworks like ZF (Not to be saying ZF doesn't have its own advantages).

Like zeusakm said, your controller is not that huge. However it all depends also, on which side of the fat controller-lean model/lean controller-fat model debate you stand at (along with the other zillion variations/styles that are out there). Personally, I prefer to keep my controller as lean as possible. If I feel my controller is doing too many things, and becoming bloated sometimes I move some of those functionalities into helpers (instead of models), mainly because I like to have my models reflect business objects. Also, when some of these tasks can be coupled together into a more well formed entity, sometimes I merge them into libraries (my own or third party)

I guess the main idea is that there is no silver-bullet right way for MVC - what works for one project might not be a good idea for another. There are many factors to weigh in. End of the day, if your code is easily maintainable, if a person can read and understand the way it is laid out without too much hassle, if people with different roles/responsiblites like Programmers/Frontend HTML designers/ Backend database coders can all work together using the framework easily without stepping (too much) on each others toes, then yes I would say your MVC is doing its job.

Also keep in mind that how URLS map out into the MVC is only one aspect of the system. This can be handled in a myriad of different ways, from mock controllers which map into a detailed model, htaccess rewrites, sometimes even MVC routers help you configure how you want URLs to resolve..