• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MVC - Controller Questions

#7
[eluser]Colin Williams[/eluser]
Quote:How did you decide to create a “cart” object.

The cart, for one, is how the user understands the process. Now, behind the scenes, in the code, we don't necessarily have to apply the same mental models we give our users, but in that case it works. The cart ties products to orders. In the real world it almost already plays a controller role. But this does not mean there's not a products controller neither an orders controller.

Quote:Obviously there is no “reports” table. Would you decide that “Reports” should be it’s own object and each report would be a method, or would you have some other methodology of deciding how to group those reports, or would they stand on there own?

Either and both. It depends on the specifics. There certainly would be one 'reports' controller that does the common stuff, like shows a list of reports, shows a single report, searches reports, etc. But there might be a need, if the reports are unique enough, to have a controller for each type of report, and equally a model. The better way, IMO, is to have one core Report controller, then have report "plugins" that extend the functionality of the Report controller in appropriate contexts. Just some pseudo code here shows you how you can use libraries to act like plugins or modules:

Code:
class Report extends Controller {
    
    function Report()
    {
        parent::Controller();
    }
    
    function add($type = 'basic')
    {
        $type = strtolower($type);
        $type_lib = $type .'_report';
        if (file_exists(APPPATH .'libraries/'. ucfirst($type_lib) . EXT))
        // If there is a Type_report.php library
        {
            $this->load->library($type_lib);
            // Now we relegate operations to methods that the libs should have implemented
            if ($this->$type_lib->run_validation())
            {
                $this->$type_lib->save_report();
            }
            else
            {
                // Load the view, form, etc... typical validation
            }
        }
        else
        {
            $this->error = 'No support for '. $type .' reports.';
            $this->add('basic');
        }
    }
}

Quote:Where would you put something simple, like…a public facing view like a homepage, or about us page.

Likely in a simple Page controller. Could just load views or flat HTML files to get the page text and not need it in the database


Messages In This Thread
MVC - Controller Questions - by El Forum - 09-27-2008, 08:40 PM
MVC - Controller Questions - by El Forum - 09-27-2008, 09:11 PM
MVC - Controller Questions - by El Forum - 09-27-2008, 11:59 PM
MVC - Controller Questions - by El Forum - 10-03-2008, 04:22 PM
MVC - Controller Questions - by El Forum - 10-03-2008, 04:44 PM
MVC - Controller Questions - by El Forum - 10-04-2008, 01:47 PM
MVC - Controller Questions - by El Forum - 10-04-2008, 04:22 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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