Welcome Guest, Not a member yet? Register   Sign In
Question Regarding Views (New to CI)
#1

[eluser]kaisama[/eluser]
I have been working on a personal project for quite some time now (nearly two years), jumping from one system to another, and soon finally giving a shot at writing my own CMS framework. That is, until I found codeigniter. I wish I found this a lot sooner, as it's exactly what I've been looking for in a PHP framework.

I do have a question though after searching the forums for the answer and coming out empty handed. So, sorry if this has been asked before and answered.

My website will use multiple themes that logged in users may choose from. My question is, do I have to have the css, images, etc folders separate from the views folder? I'd like to have the scheme as:

Code:
views/
  theme_name/
    css/
    images/
    header.php
    footer.php
    test_page.php

I found that I wasn't able to call any of the images or css files when they were within the application/views folder.

I've had to lay it out as

Code:
themes/
  theme_name/
    css/
    images/

application/
  views/
    theme_name/
      header.php
      footer.php
      test_page.php

Is it possible to work around that? And if it is, could you give me an example? Just seems weird to have things so separated like that.

Thanks for your time~
#2

[eluser]skunkbad[/eluser]
Yes, you do need to put your images and other resources at root level. This is where index.php is, which is the level where it looks from. I'd love to put them in my application directory, but this isn't possible because I have denied access to this directory through .htaccess/

In regards to your directory organization for these resources, it should be something that you understand, and that you will understand if you come back after 6 months. My organization looks like this:

/
/css/
/page_specific/
/img/
/page_specific/
/thumbs/
/large/
/js/
#3

[eluser]tomcode[/eluser]
I've written an extension for the Loader class which allows You to keep Your templates together with the other assets outside the system :
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Extends the Loader Class
*
* Loads template files
*
* @package        CodeIgniter
* @subpackage    Libraries
* @author        tomcode
* @category    Loader
*/
class MY_Loader extends CI_Loader {

    /**
     * Load Template
     *
     * like the loader view method, but from app root
     *
     * @access    public
     * @param    string
     * @param    array
     * @param    bool
     * @return    string
     */
    function template($path, $vars = array(), $return = FALSE)
    {
        return $this->_ci_load(array('_ci_path' => $path.EXT, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
    }

}

Put it in application/libraries, it loads automatically.

Your file structure

themes/
theme_name/
css/
images/
php/
system/
index.php



Use it like that :
Code:
// send to browser
$this->load->template('theme_name/php/template_name', $data);

// load into variable
$template = $this->load->template('theme_name/php/template_name', $data, true);
#4

[eluser]jedd[/eluser]
If you're hosting on a Real operating system, then you can put them wherever you like and symlink them to pretend to be where most people keep them .. if that makes sense.

I gather a lot of people keep their javascript and stylesheets (etc) under a directory called assets, up at the top of the tree. This makes the .htaccess (which most people use to remove the index.php requirement in the URL) much easier to craft.

I've been happy having my CSS files living at assets/stylesheets/{themename}/. Is it just the aesthetics / neatness of having them nearer each other?
#5

[eluser]John_Betong[/eluser]
[quote author="kaisama" date="1251011808"]
...
...
...
My website will use multiple themes that logged in users may choose from. My question is, do I have to have the css, images, etc folders separate from the views folder? I'd like to have the scheme as:
...
...
...
[/quote]
 
I prefer to keep my images outside of the application directory.
 
During development the CSS file is continually changing and is only associated with the view files so I reckon it is sensible to keep the CSS file along with the relevant view files. The CSS file is stored in the same view folder.

Here is the link that works on my localhost and online:
Code:
<link type="text/css" href="/ci_gallery/views/style_001.css" rel="stylesheet" media="all" />
 
I have just zipped and archived my ci_gallery application project and it is only 82.8kb
 
 
 
#6

[eluser]kaisama[/eluser]
Wow, what an awesome community <3 never expected to be this many posts in such a short amount of time.

Thank you everyone for their replies~ I have given them each a go round and found that I've just coped with having my images and CSS outside of the application/views folder.

I tried keeping my CSS files in with my views folder (as John_Betong suggested) but found it was neater to keep them outside as well due to the fact that my jquery themes (CSS and images) are outside the application folder. I use a sort of... "hybrid" CSS file that combines PHP so I can use the base_url variable from codeigniter to link to my images and such. I find that it works well and haven't had any problems with it. Is that good code practice? xD

And tomcode, your library seems interesting o: I may play around with it in the future with different projects ^^




Theme © iAndrew 2016 - Forum software by © MyBB