PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 21, 2022

[FIXED] Stylesheets 403 Forbidden Local Host Codeigniter

 January 21, 2022     codeigniter, css     No comments   

Issue

I am almost done with my theme system for my codeigniter.

Come across a issue with style sheets have error 403 local host.

It was working on my other one but my new version will not pick up

Each theme has its on style sheet folder and java script. Most people say its wrong to do it that way but. This way is much more better for theme system.

theme/default

theme/default/stylesheets/stylesheet.css

theme/default/javascript/common.js

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="" />
<meta name="keywords" content="" />
<title><?php echo $this->config->item('title'); ?></title>
<base href="<?php echo base_url(); ?>"> 
<link rel="stylesheet" type="text/css" href="application/views/theme/default/stylesheets/stylesheet.css" media="screen">    
</head>

theme/codeigniter

theme/codeigniter/stylesheets/stylesheet.css

theme/codeigniter/javascript/common.js

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="" />
<meta name="keywords" content="" />
<title><?php echo $this->config->item('title'); ?></title>
<base href="<?php echo base_url(); ?>" >
<link rel="stylesheet" type="text/css" href="application/views/theme/codeigniter/stylesheets/stylesheet.css" media="screen" >
</head>

Solution

I think direct access inside the applications folder will be revoked by the Code Ignitor. Hence, i put all put all images,CSS and JS in a folder named assets in the CI ROOT FOLDER, along with applications, system & user_guide.

Now, Make a file named utility_helper.php in ROOT_FOLDER/application/helper and add the following code

<?php

function asset_url(){
   return base_url().'assets/';
}

?>

then add utility to application/config/autoload.php at line 67

$autoload['helper'] = array('utility');

Now when ever you want to access the asset folder, you can call it as

<link rel="stylesheet" type="text/css" href="<?php echo asset_url();?>stylesheets/stylesheet.css" />


Answered By - Akhil Sidharth
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing