0

I'm fairly new to Codeigniter as well as MVC and I'm having a bit of trouble figuring out the best way to accomplish this.

I need to build an app that allows users to apply to various programs offered by some institutions. However, these institutions must all have a spot in the app yet they want their independence from one another—not sharing one application page for all programs. For instance Institution 1 wants a section of the site to only view and apply to their programs and Institution 2 wants a section of the site to only apply to their programs.

What is the best way to accomplish this? Should I create a separate controller for each institution?

E.g. sitename.com/inst1/apply, sitename.com/inst2/apply

Each of these controllers would essentially be identical with the same create/read/update/etc functions though. What are best practices in this situation? Thank you!

tereško
  • 58,060
  • 25
  • 98
  • 150
Vecta
  • 2,312
  • 5
  • 28
  • 47

4 Answers4

1

You can create folders to serve your functionality properly. This is widely used for APIs.

For example. You can have your folder structure like this.

- application/
    - controllers/
        - inst1/
            apply.php
        - inst2/
            apply.php

With this, you'll have the URL endpoints like.

index.php/inst1/apply
index.php/inst2/apply
Steven Lu
  • 2,150
  • 1
  • 24
  • 33
0

I think you have it right, you'd create controllers for each institution allowing you to change what data you were pulling for each. The views could be shared since all the functionality would be in the controller/model which is one of the more important aspects of MVC to begin with, the ability to separate those layers and reuse what you need where you need without duplication. If you set up your pages as a template you could even pull different templates to feed the views to that would be institution specific.

Rick Calder
  • 18,310
  • 3
  • 24
  • 41
0

For this you probably want to use the same controller and instead handle the variation through passing your function a different uri segment which you can read about here . In my codeigniter applications i like to keep a specific functionality within each controller or model. So it might look something like:

sitename.com/my_controller/my_function/my_argument

Where the function in your controller looks like:

public function my_function($argument){
//stuff goes here
}

You can of course use your routes file to make the url look however you'd like.

Will Sampson
  • 504
  • 6
  • 22
0

Just build a single controller, and make a flag to differ them. In the view file you may check for this flag to decide weather to show programs and apply or not.

Your url would be like that:

sitename.com/inst/1/apply, sitename.com/inst/2/apply

note: you may also change the numbers in the url with words; to better seo.

Ali Mohamed
  • 3,186
  • 2
  • 14
  • 6