• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it normal for a coder to have all the controllers in 1 file? Main.php

#1
[eluser]vmirjamali[/eluser]
Essentially just like the header says my coder currently coding with CI has around 2k of lines in main.php and didn't seperate them, here's a snipit:

Code:
function index() {
        $this->load->model('mdlanime');
        $this->load->model('mdlepisode');
        $this->load->helper('url');
        
        $headerData['title'] = 'Watch Anime Online for Free - Anime Episodes, Anime Shows, and Anime Movies all for Free';
        $pageData['latestReleases'] = $this->mdlepisode->GetLatestReleases();
        $pageData['topshows'] = $this->mdlanime->GetPopular(2, 0);
        $pageData['recentcompleted'] = $this->mdlanime->GetRecentCompleted();
        
        $this->load->view('vw_header', $headerData);
        $this->load->view('vw_index', $pageData);
        $this->load->view('vw_divider');
        $this->load->view('vw_sidebar');
        $this->load->view('vw_footer');
        
        $this->output->cache($this->config->item('cacheTime'));
    }
    
    function sidebar() {
        session_start();
        $this->load->helper('url');
        
        if ($this->vbuser->info['userid'] > 0 && !isset($_SESSION['points'])) {
            $this->load->model('mdluserpoints');
            $_SESSION['points'] = $this->mdluserpoints->Get();
        }
        if ($this->vbuser->info['userid'] > 0) {
            $this->vbuser->create_session($this->vbuser->info['userid']);
        }
        
        $this->load->view('vw_sidebar');
    }
    
    function login() {        
        $headerData['title'] = 'Watch Anime Online for Free - Anime Episodes, Anime Shows, and Anime Movies all for Free';
        $pageData['message'] = '';
        $pageData['loggedIn'] = false;
        
        // Process login
        if (isset($_POST['login'])) {
            // Set field requirements
            $this->load->library('form_validation');
            $this->form_validation->set_rules('username', 'username', 'trim|required|min_length[1]|max_length[100]');
            $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[1]|max_length[100]');
            
            if ($this->form_validation->run() == true &&
                $userid = $this->vbuser->is_valid_login($_POST['username'], $_POST['password'])) {
                $this->vbuser->create_session($userid);
                $pageData['loggedIn'] = true;
            }
            else {
                // Failed login
                $pageData['message'] = 'Invalid username or password.';
            }
Is that something needed in CI or is it bad coding practice as i do need scalability with my site? I heard that in other frameworks you can split the controller to many files, so any ideas? Thanks

#2
[eluser]Dam1an[/eluser]
There's also a poster on the forum who doesn't use [ code ] tags Tongue
Is that also normal?

#3
[eluser]vmirjamali[/eluser]
Yea when it get's cutoff due to too many charactars, and somehow get's through it becomes normal Smile lol flame baitSmile

So is there a way to split the controllers or does CI force you to use only 1 controller? Thanks

#4
[eluser]Dam1an[/eluser]
Yeah you can have as many Controllers as you want, typically one for each area of functionality, so you could have one controller for users, one for messages, one for items etc. And each controller would have functions within that context, such as add, edit, delete, view etc

See the UserGuide for more info

#5
[eluser]gunter[/eluser]
hm, did you mean all the functions in one file?
I don´t really understand your posting.. :-)

#6
[eluser]vmirjamali[/eluser]
Yea I think the coder routed everything through 1 controller which is called main.php :| As in main.php get's deleted the entire site dies. Grr I hate my coder.

#7
[eluser]Colin Williams[/eluser]
If you hate to be organized and orderly go for it. If you want a maintenance headache, go for it. If you don't want each request to be optimized, go for it.

#8
[eluser]Thorpe Obazee[/eluser]
Wow. One controller for the whole site? I can imagine how he will organize stuff for that.

#9
[eluser]vmirjamali[/eluser]
Lol believe me if i wanted it I wouldn't be asking here if what he's doing is right or wrong. Knowing that it's doable on CI (splitting controllers) it's time to find a new coder that'll do it.

Anyone was to step up the place and finish an incomplete project or at least let me know if it's easy to split the main.php into many controllers?

Man I wish I knew more about the whole framework stuff before allowing him to get myself into this mess.

Thanks for letting me know.

#10
[eluser]wiredesignz[/eluser]
If your instructions included for him to provide maintainable code you may have a point, otherwise there is nothing wrong with the job he has done for you.

I have seen worse code, But really it seems to me you are getting exactly what you paid for.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.