I am developing a small project that has user and admin sides. In my controllers folder there are two folders admin and user. Similarly in my views folder there are two folders admin and user. Both admin and user ends have different templates. I have placed CSS/Images/JS in assets folder that is placed in root folder (parallel to system folder). I do not want to make two different folders in assets folder for admin and user. Instead what i want is to place respective css/js/images in views/admin and views/user folders. This way i can remove assets folder and all html/css/images etc will be in same folder and i will be able to make different themes for user side. Is it possible?? If yes how?? Please guide me in detail.
edit: I want to place admin.css in application/views/admin and user.css in application/views/users
anyone who want to place all css/js/images in views can try this.
for example you want to place css file in views folder you will give CSS file path like this
href="<? echo base_url() ?>application/views/assets/css/admin.css"
now you will get forbidden access error. This error is cause of .htaccess file in application folder. open .htaccess file and copy paste following.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
You are ready to go..
Load the URL helper in the controller.
Then in views you can use
<link rel="stylesheet" href="<?= base_url() ?>assets/css/admin.css" />
<link rel="stylesheet" href="<?= base_url() ?>assets/css/user.css" />
off course change the path to the css file as required.
You can have separate folders then in your controller construct, change $this->load->_ci_view_path = {theme folder}.
Example: I store the templates information in a database table so,
$this->db->where('published', 'Y')->limit(1);
$res = $this->db->get('templates')->result();
$this->load->_ci_view_path = $res[0]->template_folder;
add one folder any name e.g public and add .htaccess file and write allow from all
it means, in this folder your all files and all folder will not give error Access forbidden!
use it like this
<link href="<?php echo base_url(); ?>application/public/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url(); ?>application/public/js/javascript.js"></script>
etc
Related
I'm trying to develop a shopping system with codeigniter.
I developing the back-end & front-end of my shopping system.
But my problem is I want to use this code for many stores.
For example my main address is shop.com.
I want people can have their own shop in my system with their own subfolder like this: shop.com/shop1 | shop.com/shop2 & ...
I want the users subfolder placed out of application folder.
My directory list like this:
shop.com
-application
--cache
--config
--controllers
--core
--helpers
--...(other application contents)
-assets
-attachments
-system
-shop1
-shop2
& ...
I making all shop parts and every thing is ok when i call shop.com.
Now I want to making shop1 with specific subfolder and database.
I can making separate database for each shop and connect the code to his own database. after this I call shop.com/shop1 and the main page load like a charm.
But when I call shop controllers ( example: shop.com/shop1/checkout ) I get 404 error.
And at the end I noticed two point:
1- I use the original codeigniter root index.php code as my shop1/index.php
2- I change the $system_path to ../system and $application_folder to ../application
It seems codeigniter unable to locate the controllers properly.
What can I do to solving this problem?
You mean HMVC?
Download files and copy C.i.3.0 forder in application : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads
Create and coppy paste in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
3.Create folder name 'modules' in application/
4.Create folder name 'folder' in application/modules
4.Create folder name 'controllers, models, views' in application/modules/folder
5.Create file name 'file name same folder' in application/modules/folder/controllers
for error
paste this in MX/Loder.php
return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
Why i can't get an image to work. I'm trying this:
background-image: url(jBootstrap/images/ui-icons_222222_256x240.png);
and it doesn't work. When i'm trying to access it trought URL i get an error:
Asset [stylesheets/jBootstrap/images/ui-icons_222222_256x240.png] was unable to be processed.
Can't get any images, tried in many variations of directories and still doesn't work. When i'm doing this on plain html-css it works perfectly, but not in laravel. What am I doing wrong ?
btw, i'm using Basset if it helps.
EDIT 1
Also including the additional information about a partial structure of my public folder and html link generated by basset:
public/
stylesheets/
jBootstrap/
images/
ui-icons_222222_256x240.png
main.css it contains the background-image...
when including the css file, in source code i see:
<link rel="stylesheet" type="text/css" href="http://localhost/Job/worker/myapp/public/7n3C5wypAmTi8VT8/application/stylesheets/main.css" />
Edit 2
Adding my public/.htaccess file:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Edit 3
Tried another way:
public/stylesheets/main.css
public/stylesheets/abc.jpg
in main.css I have code: body { background-image: url('abc.jpg') } and i'm getting nothing ...
Please help, struggling 2 days now ...
Found the problem... It was Basset package, it wat required to put $collection->apply('UriRewriteFilter'); into configurations.
I would naturally assume that one (or both) things are incorrect here:
Your .htaccess file is not checking for existing files when rewriting. Check to see if RewriteCond {%REQUEST_FILENAME} !-f exists in that file.
You are not requesting your background image from the root, i.e. absolutely. Try requesting the resource using a leading slash. For example, instead of calling foo.png, try calling /foo.png.
Try using setArguments('../') on your collection
'collections' => array(
'application' => function($collection) {
$collection->add('../vendor/twitter/bootstrap/less/bootstrap.less')->apply('Less');
$directory = $collection->directory('assets/stylesheets', function($collection) {
$collection->add('main.css');
})->apply('UriRewriteFilter')->setArguments('../')->apply('CssMin');
}
),
This did the trick for me.
I have my site under the structure: www.somesite.com/index.php?page=p_section_page.php
I want my site to display something like: www.somesite.com/section/page OR just www.somesite.com/page/
Tried to write rules in the .htaccess file like so:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule PAGE index.php?page=p_section_page.php
It works fine if i try www.somesite.com/page/ but the images, css files and js, try to access the www.somesite.com/page/css/ or www.somesite.com/images/ directories which clearly do not exist.
Any help here? Thanks!
My educated guess is that you are using relative paths. If you change the URL of the HTML document you change the effective path of pictures, scripts and other resources that are loaded via relative paths. It's the same as when you move the file to another directory.
I find it easier to call resources with absolute paths. You are using PHP so you have two options: hard-code the leading slash or use PHP to set it:
<img src="/images/picture.jpg" ... >
<img src="<?=$_SERVER['DOCUMENT_ROOT']?>images/picture.jpg" ... >
I wrote a utility to handle the versioning of my CSS and JS files for caching purposes, however, I'm struggling to get the RewriteRule setup correctly to load the original file.
The way the versioning utility writes the new URL is as below:
Local
<script src="20110125/contact.js" type="text/javascript"></script>
Global
<script src="../Scripts/js/20110125/core.js" type="text/javascript"></script>
My RewriteRules strip out the timestamp and load just the path and filename. They are as follows:
#rewrite core js
RewriteRule ^(\/Scripts\/[a-z]*\/)[0-9]*\/(.*) $1$2 [NC]
#rewrite directory level js
RewriteRule .+\/(.+\.js) $1 [NC]
However, when I make a page request I get a 404 on the pages. Any help is appreciated.
You have a rather bizarre path to your JS files; I'd recommend just using /js or /javascript, and don't use capital letters in file or path names in a URL. What are you trying to do with your second RewriteRule?
# /js/123456/jquery.js to /js/jquery.js
RewriteRule ^/js/[0-9]+/(.+).js$ /js/$1.js [L]
I have a bit of an odd problem with my CodeIgniter installation, I am using modrewrite in order to shorten my URLs, for example I have an api page:
http://www.mydomain.com/api
And it works really well, my .htaccess file looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
But whats really strange is if I type a trailing slash:
http://www.mydomain.com/api/
The API page loads ok but it doesn't include the Base CSS file which is included on all the pages, it would be fine if it didn't load anything at all, but I need to stop it from loading the actual api page. Any advice would be helpful,
Thanks!
UPDATE: I have found that when I view source my CSS file comes from the following when the CSS loads correctly:
http://www.mydomain.com/css/all.css
But when it fails to load it comes from
http://www.mydomain.com/api/css/all.css
Make sure that you have a trailing slash in your base_url in the config.php file:
$config['base_url'] = "http://www.mydomain.com/";
And always call the base_url() when dealing with links...etc
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/all.css">
EDIT:
Please note that I'm using the mod_rewrite from this wiki page BUT since my CI installation in not on the root (inside /ci173/) the RewriteBase is not / but /ci173/.
When using relative URL path like css/all.css or ./css/all.css (both are equivalent), you need to be aware that relative URL paths (like any relative URLs) are resolved using a base URL that is the URL of the current document if not specified otherwise.
So in your case /api or /api/ is the base URL path and the relative URL path css/all.css is resolved differently depending on the base URL path:
/api + css/all.css → /css/all.css
/api/ + css/all.css → /api/css/all.css
To conquer this you either need to
use absolute URL paths like /css/all.css that are independent from the base URL path
specify a different base URL in your HTML document (e.g. /); but note that this will affect all relative URLs and not just relative URL paths
adjust your relative URL paths to suite your base URL paths:
for /api use css/all.css
for /api/ use ../css/all.css
for /api/foo/bar/ use ../../../css/all.css, etc.
I guess the first solution is the easiest.