Welcome Guest, Not a member yet? Register   Sign In
Organizing views and assets
#1

[eluser]Boris Strahija[/eluser]
I'm working on a pretty big CI project and I would like to know what is the best way for oganizing your views and assets.
I was thinking of doing something like this:

Views:
/system/application/views/backend/ - for all my backen views
/system/application/views/frontend/ - for the frontend views

Assets:
/system/assets/backend/
/system/assets/frontend/


This looks pretty good to me, except I would like for my URL's in the frontend to look something like this:
<link rel="stylesheet" href="/css/style/" type="text/css" media="all" charset="utf-8" />

Maybe I should create a controller that would read my CSS files in the assets/frontend folder, and echo them?

Any suggestions? How do you do it?
#2

[eluser]pistolPete[/eluser]
[quote author="Boris Strahija" date="1234806403"]
Maybe I should create a controller that would read my CSS files in the assets/frontend folder, and echo them?[/quote]

I'd rather use mod_rewrite in a .htaccess file.
#3

[eluser]TheFuzzy0ne[/eluser]
I'd do an advanced search on this Web site for the phrase "asset management".
#4

[eluser]umefarooq[/eluser]
for your js and css files you can use the following library its work really nice it can combine your different css or js files and make it one file while viewing. have look on it

http://ellislab.com/forums/viewthread/105693/
#5

[eluser]JulianM[/eluser]
Hi. I'd like to hear your opinion. I used to use the default structure for CodeIgniter projects but after about 1.5 years since I am using CodeIgniter I realized that I don't like to have the application folder inside the system folder, so I moved it one top level.

Now, I am wondering about the overall files. This is a review of my common structure nowadays:

Code:
+ application
+ system
+ themes
|-+ default
  |-+ css
    |-+ common
      |-+ common.css
    |-+ homepage
      |-+ homepage.css
    |-+ admin
      |-+ admin.css
    |-+ layout.css
    |-+ theme.css
  |-+ images
    |-+ common
    |-+ homepage
    |-+ admin
+ js
  |-+ common
    |-+ common.js
  |-+ homepage
    |-+ homepage.js
  |-+ admin
    |-+ admin.js
  |-+ jquery.js
+ index.php

As you can notice, I have divided the themes in multiple possible themes (based on the idea of switchable themes). Also, I have used separated folders for independent pages with a different treatment, ie: css/homepage or css/admin . The same idea applied for javascript

Instead of using <a href="http://ellislab.com/forums/viewthread/105693/">Carabiner</a> library, I have used my own css and javascript rules for adding custom files in my views/controller. This was really flexible for me. (I can explain in a different post how I use it if anyone is interested.)

For view files, I use to have one page template that references a header, footer and a placeholder for a subpage inside. Then I use the same organization than before with view/homepage, view/admin/edit.php, view/admin/list.php to format each independent page.

Any thoughts?

Julian
#6

[eluser]Jamie Rumbelow[/eluser]
I put a simple /assets folder, with /css, /js and /img folders inside it. Then I can link as a path and it runs fine.
#7

[eluser]JayTee[/eluser]
[quote author="Boris Strahija" date="1234806403"]I'm working on a pretty big CI project and I would like to know what is the best way for oganizing your views and assets.[/quote]
"Best" is always subjective - so I can only tell you what I do; which I think is "best" for my style.
[quote author="Boris Strahija" date="1234806403"]I was thinking of doing something like this:

Views:
/system/application/views/backend/ - for all my backen views
/system/application/views/frontend/ - for the frontend views

Any suggestions? How do you do it?[/quote]
I keep a very detailed folder structure for my views. They are grouped based on function/location rather than what you're suggesting.
Example:
Let's say there are three main sections of my site: public, admin, members
For each of those sections, there are some common views like navigation and login forms

here's two ways I've set things up on sites
1. the "group by page location" style
application/views
|_navigation
| |_admin_nav.php
| |_public_nav.php
| |_member_nav.php
|_common
| |_login.php
| |_forgot_pass.php
|_home_page
|_admin_home.php
|_public_home.php
|_member_home.php

2. The "group by site section" style
application/views
|_admin
| |_admin_nav.php
| |_admin_home.php
| |_admin_layout.php
| |_admin_whatever.php
|_public
| |_public_nav.php
| |_public_home.php
| |_public_whatever.php
|_members
| |_member_nav.php
| |_member_home.php
| |_member_whatever.php
|_common
|_common_login.php
|_common_forgot_pass.php
|_common_whatever

I generally prefer #2 because I find it easier to locate what I need. I prefix my file names with the site area so that I can quickly identify what I'm working on in my IDE.

Quote:Assets:
/system/assets/backend/
/system/assets/frontend/
I'm not sure how you define "assets" - but I define those as the js, css, image, and other files that aren't part of the framework. I keep all of that in a folder I call "public" which rests in the root folder of the site
/
|_public
| |_css
| |_js
| |_img
| | |_icons
| | |_photos
| |_files
| |_docs
| |_pdfs
|_system <-- CI system folder

In my view files, everything renders off the site_url():
Code:
//using the HTML Helper:
echo link_tag('public/css/mystyles.css');
//&lt;link type="text/css" rel="stylesheet" href="http://www.example.com/public/css/mystyle.css" /&gt;

To go a step further, I actually use a css/js combining file that gzips those files before being sent to the browser:
http://rakaz.nl/extra/code/combine
#8

[eluser]JulianM[/eluser]
I really appreciate the Combine script. Smile Very useful. Thanks.
#9

[eluser]TheFuzzy0ne[/eluser]
[quote author="JayTee" date="1236473944"]To go a step further, I actually use a css/js combining file that gzips those files before being sent to the browser:
http://rakaz.nl/extra/code/combine[/quote]

I assume said library knows which browsers actually support gzip compression?

Thanks for the pointers. Very insightful as always.
#10

[eluser]JayTee[/eluser]
[quote author="TheFuzzy0ne" date="1236474391"]I assume said library knows which browsers actually support gzip compression?.[/quote]
From the website:
Quote:Combine 0.5
- Do not use compression with certain versions of Internet Explorer
- Determine what type of compression is supported before loading the cache
- Slight change in the naming convention for cache file




Theme © iAndrew 2016 - Forum software by © MyBB