Welcome Guest, Not a member yet? Register   Sign In
How to structure my site
#1

[eluser]Hamilogre[/eluser]
I'm new to CI, I think I have read the entire user guide, and wiki, and I have also read a lot on the forums. I have a question about how to structure my application.

The site is for a doctor's office where there are 7 doctors in the practice. I want to build a backend for the practice administrator to be able to edit things herself so it doesn't require code changes when things need to be updated. What I'm working on now, is the doctor's main page that lists all the doctors, and the individual doctor's pages that shows their bio.

For the doctor's page, I want my URL to be http://www.mysite.com/doctors. (Fine, all I do is tell the index function to load the doctors/index view, as shown below:

Code:
function index()
{
    $this->load->view('doctors/index');
}

Now for each individual doctor, I want the URL to be: http://www.mysite.com/doctors/doctorlastname and I'm not sure how to setup my functions in the doctors controller to do this, so that my site is truly dynamic. If I setup a function for each doctor's last name, that would defeat the purpose of making it dynamic, as I want to only store each doctor's name 1 time in my database.

What I have come up with is to have a function called bio in my doctors controller to load the view of the appropriate doctor. Then I configured my routes to do this:
Code:
$route['doctors/:any'] = "doctors/bio"

And here is my bio function:
Code:
function bio()
{
    $this->load->view('doctors/' . $this->uri->segment(2));
}

I think this function may need some reworking too, it seems to simple to me, any suggestions?

That works fine, but now what if I want to make a url to edit the bio something like this: http://www.mysite.com/doctors/doctorlastname/edit. How do I set it up so that that url doesn't get routed to doctors/bio.

One question about views too. Say the above code segment loads the view doctors/smith. In my doctors/smith view, it it appropriate for me to call my header and footer view from within the doctors/smith view? Not sure what the best way to set this up is. I noticed that you can only call one view from a controller.

Here is what my doctors/smith view would look like:
Code:
<?php $this->load->view('global/header'); ?>
<p> Dr. Smith Bio</p>
&lt;?php $this->load->view('global/footer'); ?&gt;

Is this the proper way to include my header and folder?

I think I am close to fully understanding how this works, but I need some assistance getting a grasp on it. Any help would be appreciated.

Thanks.
#2

[eluser]Michael Wales[/eluser]
You would setup the /doctors/smith/edit URI routing the same way you did the other.
Code:
$route['doctors/:any/edit'] = 'doctors/edit';
The miracle (curse?) or URI routing is you have to do it with everything that begins with your defined URI. For example, if you had 'doctors/list' - Code Igniter wouldn't know what to do with it now that you have started re-writing that URI. You will have to define this route in your URI routing.

Remember, routing is done from the top to the bottom (and I have had experiences where the top-most route doesn't work - anyone else?).

As for your header/footer - that is one way to go about it.
#3

[eluser]esra[/eluser]
[quote author="walesmd" date="1187409897"]Remember, routing is done from the top to the bottom (and I have had experiences where the top-most route doesn't work - anyone else?).[/quote]
Yes. I tried to isolate this once out of curiosity. The are some PHP4 version specific workaround solutions in Router.php that might have something to do with it.
#4

[eluser]Hamilogre[/eluser]
Cool, this helped. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB