Folder Structure - Am I doing correctly?

#1
[eluser]Jeffrey04[/eluser]
I'm not sure whether I am doing correctly but following is my folder structure

app
|-controller
||-module
|||-main.php // default controller
|||-add.php // for adding records
|-model
||-module
|||-module_model.php // storing the model for a module
|-view
||-module
|||-module-action-name.php // storing template

however, having a controller class named 'add', I am getting some problem with scaffolding because when I want to add a record, i get to http://project.tld/codeigniter/module/add/ which is my 'add' controller class???

#2
[eluser]gtech[/eluser]
your question seems a bit vague so I will try and interpret what you are trying to do

If you have quite a small application there is no real need to split the controllers or models into subdirectories.

It sounds like your creating a controller class for every method you want to call which is not necessary as a controller and model can have multiple methods. Say I had a users table, I may want to create a users controller and model eg.

|MODELS
||usersdb.php
|CONTROLLERS
||users.php

the model and controller can then have different methods eg, add a user, remove a user, view all users etc.

Code:
class Usersdb extends Model
{
  /**
   * The Initialisation method
   */

  function Usersdb()
  {
    parent::Model();
  }
  function add($name)
  {
    ...
  }
  function delete($userid)
  {
    ...
  }
}

Code:
class User extends Controller {

  function User()
  {
    parent::Controller();
    $this->load->model('usersdb');
    $this->load->scaffolding('users');
  }
  function add()
  {
     $name = 'test';
     $res = $this->usersdb->add($name);
     $data['res'] = $res;
     $this->load->view('users/user_add_v', $data);
  }
  function delete($id)
  {
     $res = $this->usersdb->delete($id);
     $data['res'] = $res;
     $this->load->view('users/user_remove_v', $data);
  }

so to add a user you would use the URL

whatever.com/codeigniter/index.php/user/add

or am I misinterpreting your problem?

#3
[eluser]Tom Glover[/eluser]
Well said, I hope this helps you Jeffrey04, and also if you are creating a big app you may want to look into HMVC or Matchbox.

#4
[eluser]Jeffrey04[/eluser]
Big Grin i have re-organized the file structure so that it is more straight forward... but I'm still not very used to having all controller classes saved in a single directory Tongue

#5
[eluser]gtech[/eluser]
by all means split them into subdirectories if it makes sense, eg you may have an admin interface you might want to put the administration controllers in the admin directory.. all I was trying to get at is that you can have more than one method in a controller. I tend to have a controller for each table I have in my database. As WakeyWebs suggested HMVC and matchbox are also useful. I know matchbox is used to organize your CI projects modularly, I have not looked into HMVC.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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