Welcome Guest, Not a member yet? Register   Sign In
css as plugin
#1

[eluser]Unknown[/eluser]
Sorry but I'am new to Code Igniter.
I have problem with css and after reading forum for css, I come with my own solution.

This was my step to overcome my css link problem.

1) I make a folder in system as css. This folder will store css and its file.
for my example I download superior css from http://www.freecsstemplates.org

2) I put the style and image in the file like this:
style path = system/css/superior/style.css
image path = system/css/superior/image/ (image is folder)

3) in plugin, I add my plugins to call the css like this:
plugin name = superior_css_pi.php
content =
<?PHP
$path = 'http://'.$_SERVER['HTTP_HOST'].'/system/css/superior/style.css';
?>
<link href="<?PHP echo $path;?>" rel="stylesheet" type="text/css" media="screen" />

4) Then I call the plugin from view like this:
<html>
<head>
<?PHP $this->load->plugin('superior_css'); ?>
</head>
<body>
.......
</html>

it work for me but will this affect code igniter process, will it slow code igniter down?

one major problem is when I open my server page with firefox, it turn out to be ok. But when I open my server with IE the templates not align in center, it align to left side of IE. Can anyone help?
#2

[eluser]xwero[/eluser]
First it's best not to add public assets as css and images to a framework related directory. There is a chance you move the framework related directories above the public directory and then your assets will not be callable.

Just use base_url to get the url and if you want you can extend the url_helper with a css_url and img_url function based on the base_url function.
#3

[eluser]Dam1an[/eluser]
First of all, that seems like a lot of overhead to load a CSS file, the general way to do it is
Code:
// Make sure URL helper is autoloaded
<link rel="stylesheet" href="<?=base_url()?>css/style.css" type="text/css" media="screen" />

Alternativly, you can extend the Loader class (PHP5 only)
Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Loader extends CI_Loader {
    public function __construct() {
        parent::CI_Loader();
    }
    
    public function css($css, $media = 'screen, projection') {
        echo '<link rel="stylesheet" href="css/'.$css.'.css" type="text/css" media="'.$media.'" />'."\n";
    }
}
?>

and then you can use
Code:
$this->load->css('style');

The above assumes you have a css directory in your application directory
#4

[eluser]Thorpe Obazee[/eluser]
@OP. You shouldn't put adding or modifying things in the systems folder. You could probably create a helper for loading css files.
#5

[eluser]xwero[/eluser]
Dam1an you like to extend classes i see Smile Extending a class is overkill to add a functions like this.
#6

[eluser]Dam1an[/eluser]
[quote author="xwero" date="1241016165"]Dam1an you like to extend classes i see Smile Extending a class is overkill to add a functions like this.[/quote]

I do have more stuff in my extended loader, I just removed all the irrelevant stuff
And the only reason I'm using the loader for css in my current project, is that the style sheet to use isn't always the same, its a per user option (sure I could pass the name into the view, but I prefer this way, as I already had the Loader class extended)

And you mean to say creating a plugin isn't overkill for something like this Wink
#7

[eluser]xwero[/eluser]
A plugin is less overkill because it doesn't changes the core of the application. Having an easy way to add the css and image path is trivial as you don't have to do it in php. You can use the base tag for relative asset paths.

If the style sheet changes use a default setting in the config and change it if needed.

Extending classes is an option you have to think about as last option.
#8

[eluser]Dam1an[/eluser]
[quote author="xwero" date="1241018441"]
Extending classes is an option you have to think about as last option.[/quote]

I didn't really think about it like that
I just thought, its similar functionality, so I just extended the Loader class.

And technically, I'm not changing the core Tongue I'm extending
#9

[eluser]jdfwarrior[/eluser]
Not using a predefined stylesheet for every page/user can be done without extending the loader class easily. I don't know that I agree with Dam1an's way of being overkill. Everybody has their own method of doing things. Just because it's not the same as the next guy doesn't mean it's wrong. Unless it's just a horrifically inefficient way of doing it, its not wrong, it's just another way. Good job Dam1an.
#10

[eluser]xwero[/eluser]
jdfwarrior there are different ways of doing things but every way has its consequences and this is what should be considered.

The reason why i think extending classes is the last option is because if you do something wrong in the extended class this can have effect on the parent class. Which means the debugging is going to be more difficult.
Another reason is if you extend classes quickly it's likely app specific methods are going to appear in extended classes making the extended class less of a candidate for reuse, which could mean you copy paste the methods you need every time to the extended class in all the different apps.

And as i mentioned earlier you have to consider what the method does too. Not every function needs to go in an extended class. I get the feeling some people use extended classes as another way to autoload methods.

I think Dam1an knows what he's doing but there are a lot of posts from him where i see him extending classes, this could give the impression extending classes is good for everything.




Theme © iAndrew 2016 - Forum software by © MyBB