Reputation: 1478
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
Upvotes: 2
Views: 10733
Reputation: 67
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
Upvotes: 0
Reputation: 1478
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..
Upvotes: 4
Reputation: 11
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;
Upvotes: 0
Reputation: 11490
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.
Upvotes: 0