Welcome Guest, Not a member yet? Register   Sign In
Converting an old site to CI (Static Pages)
#1

[eluser]oldblueday[/eluser]
Hello all,

I would like to convert my current site to CI. I've just finished the net-tuts tutorials and reading the User Guide and still have a few questions.

My site is very content heavy, meaning not a lot of calculations or database access (though there is some). It's mainly for static pages.

Where do you store javascript files? -- I'd guess: /system/js/
Where do you store images for views? -- I'd guess: /views/images
When you have a hundred or so pages of different content, wouldn't that make for a lot of view files in that directory? I know the view folder can be arranged with subfolders, but is this the way it's commonly done, the standard practice?

Here's my site, if it helps clarify: www.rushemergencymedicine.com

Thanks,

Rahul
#2

[eluser]mddd[/eluser]
Don't store any static assets (like images, js files) inside the system folder. The system folder is off-limits to the end user. It is solely for CI to do its work. Everything that is a CI request goes through index.php, therefore: don't link directly to enything inside the system folder.

Just put your assets in folders next to /system. Like this:
Code:
(view of the web root)
.htaccess
index.php
robots.txt
/system
/js
/img
/css
... whatever other kinds of static assets you like to use

From your CI code you can easily refer to an image using /img/myimage.jpg. Or a js file: /js/jquery.js.

If you want to make things a bit more flexible, you can use base_url which you set in config.php. Then you load the image using <?=base_url()?>img/myimage.jpg. This has the advantage of being able to move the entire site, including assets easily into another folder. Some people like to define a location for static content, so they can move it to anywhere they like. For instance by defining a location in constants.php or using a config variable. I still think if your site is just going to be in the web root, linking to /img/myimage.jpg (etc) works fine and is easy to understand for anyone.

About view files: if you have tens or hundreds of them, I'd say it might be a good idea to store the content in a database in stead of working with individual files. That said, it is not a requirement. If you order them logically there is nothing inherently wrong with using many view files.
#3

[eluser]oldblueday[/eluser]
There's an inherent structure to storing these files right now. For example, I'll have

Code:
/students/week1/chest_pain/pnuemonia/
/students/week1/chest_pain/pneumothorax/
...
/students/week2/trauma/head_trauma/
...
/students/week3/tox/tylenol/


in which I'll store the pneumonia.php file (with model, view and controller all squashed in that one file), and images and other resources for pnuemonia in that same folder. Then there'll be a second folder where similarly all the pneumothorax-related stuff will be kept. This has allowed me to rearrange the curriculum by just moving around folders.

So in the MVC order, I should pull the application folder out of the system folder and move the system folder out of the publicly accessible area? Application, with its corresponding model, view and controller folders goes in the public area or outside as well? And if so, then the index.php, javascript and image folders go in the publicly accessible area?

Code:
/system

/application
  /config
  /autoload
   ...
  /model
  /view
    pneumonia.php
    pneumothorax.php
    heart_attack.php
    appendicitis.php
    head_trauma.php
    meningitis.php
  /controller


/public_html
  /images
    pneumonia_x_ray.png
    pneumothorax_x_ray.png
    heart_attack_ecg.png
    head_trauma_ct.png
  /javascript
  index.php

If the images were stored in a separate folder than the views, doesn't this make moving things around more difficult?

I'm not sure how to store all of this in a database. Just cut and paste the HTML code into the DB with a the page_title in a different field and use the same view to load them all? I am continually editing the content, which would be more difficult from database fields.

Thanks again for your help.
#4

[eluser]mddd[/eluser]
No, you shouldn't take the application folder out of the system folder (although it is possible, for instance when using multiple applications on a single server, sharing the system folder).

I think you need let go of thinking in a 'folder structure' way. In CI, the structure is provided by the way you set up Controllers and their Methods. You can make things smarter using Routes (being able to dynamically assign certain urls to be executed by certain controllers/methods).

So: the way the site look from the outside is determined by your controller/method structure, and possibly your routes. Then, where you store all the parts is completely separate from that. You could just have 1000 views named 1.php, 2.php etc. All in one 'views' folder. But you could still call those views from urls like /students/week1/chest_pain/pneumothorax/ if you set up your controllers to load the right views based on the information in the url.

But, if your site structure is so closely related to the folder structure and you are editing all the files directly, I think maybe you should just leave it the way it is. There won't be much benefit in pushing everything in a CI "skin". CI is good for looking stuff up based on parts of the url. If your url's are structured already and there is no wish to use a database to store everything, why not keep working in the raw html? There's nothing wrong with that.
#5

[eluser]danmontgomery[/eluser]
[quote author="mddd" date="1279303274"]No, you shouldn't take the application folder out of the system folder [/quote]

Most would disagree with this, although it is personal preference. It's generally considered good practice to move both the application and system folders out of a web-accessible location (these folders are separated by default in 2.0).

The rest of what's said I agree with. I create an 'assets' folder alongside index.php:

Code:
index.php
  /assets
    /css
    /js
    /images
#6

[eluser]mddd[/eluser]
@noctrum:
Just to clarify, I didn't mean it in a general sense, that one should not put /application out of /system.
Just that it was not going to give TS the solution he was looking for.
#7

[eluser]danmontgomery[/eluser]
[quote author="mddd" date="1279304087"]@noctrum:
Just to clarify, I didn't mean it in a general sense, that one should not put /application out of /system.
Just that it was not going to give TS the solution he was looking for.[/quote]

Gotcha Wink
#8

[eluser]oldblueday[/eluser]
[quote author="mddd" date="1279303274"]I think you need let go of thinking in a 'folder structure' way. In CI, the structure is provided by the way you set up Controllers and their Methods. You can make things smarter using Routes (being able to dynamically assign certain urls to be executed by certain controllers/methods).[/quote]

Ah, I'll have to think more on this then. So you'd suggest something like this perhaps?

Code:
class Chest_pain extends Controller
{

  function Pneumothorax ()
  {
    $this->load->view('week1/chest_pain/pneumothorax.php');
  }

  function Pneumonia ()
  {
    $this->load->view('week1/chest_pain/pneumonia.php');
  }

}

Or moreso have all the views stored in one folder and imply the order by the controller?

Code:
class Chest_pain extends Controller
{

  function Pneumothorax ()
  {
    // if user selects Week 1, chest pain, pneumothorax, then load...
    $this->load->view('pneumothorax.php');
  }

  function Pneumonia ()
  {
    // if use selects Week 1, shortness of breath, pneumononia, then load...
    $this->load->view('pneumonia.php');
  }

}


[quote author="mddd" date="1279303274"]But, if your site structure is so closely related to the folder structure and you are editing all the files directly, I think maybe you should just leave it the way it is. There won't be much benefit in pushing everything in a CI "skin". CI is good for looking stuff up based on parts of the url. If your url's are structured already and there is no wish to use a database to store everything, why not keep working in the raw html? There's nothing wrong with that.[/quote]

You're probably right. My site isn't using a lot of database access here, but it does in a few other areas (getting student evaluations, storing it in a database, creating their grades, mailing it to their school, etc). And though I plan to add more (online quizzing features, etc), it will probably only be a small part of the site in comparison to the reading material.

Honestly, I just want to learn how to use CodeIgniter in a real context PLUS I like some of the built-in security features and other helpers/libraries which I've just been writing myself.

Thanks for the responses. I'm impressed with how helpful everyone is.

- Rahul
#9

[eluser]oldblueday[/eluser]
For the benefit of anyone who may have the same questions, here were my solutions:

1) I did move the /system folder out of publicly accessible folder. All I had to do is change the location of the /system folder in the index.php file.

2) All "assets" I stored next to the index.php folder as suggested by noctrum.

Code:
/application
index.php
/assets
   /css
   /js
   /images


This works well when using the asset_helper functions to load things. The downside of this is that images are not stored near pages that use them - a tradeoff I was willing to make.

3) Instead of writing one function (within a controller) for each of the many static pages, I made one function that took arguments from the url. So I didn't do this...

Code:
/* WHAT I DIDN'T DO
* pages will be called like this
* http://www.rushemergencymedicine.com/index.php/chest_pain/pneumothorax
*
*/
class Chest_pain extends Controller
{

  function Pneumothorax ()
  {
    // if user selects Week 1, chest pain, pneumothorax, then load...
    $this->load->view('pneumothorax.php');
  }

  function Pneumonia ()
  {
    // if use selects Week 1, shortness of breath, pneumononia, then load...
    $this->load->view('pneumonia.php');
  }
}

but instead did this...

Code:
/* WHAT I DID DO
* pages will be called like this
* http://www.rushemergencymedicine.com/index.php/lectures/show_lecture/pneumonia
*
*/
class Lectures extends Controller
{
  function show_lecture($lecture_name)
  {
    $data['main_content'] = $lecture_name;
    $this->load->view('template', $data);
  }
}

/*
* then the view would look like this
* /

$this->load->view($main_content);

For me, switching to CI was helpful in (1) teaching me how to use CI, (2) for the little time savers in making emails, anchors, form validation, and the few database accesses I do, and (3) seems to make the code more portable to move to other sites.

Thanks all,

-Rahul




Theme © iAndrew 2016 - Forum software by © MyBB