Welcome Guest, Not a member yet? Register   Sign In
Relative URLs, or Absolute URLs?
#8

[eluser]wiredesignz[/eluser]
application/helpers/asset_helper.php

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

    function asset($type = 'css', $source = NULL, $attrib = NULL, $relativeURL = TRUE)
    {
        $href = ($relativeURL) ? '' : base_url();
        
        $source = $href . str_replace(".{$type}", '', $source);
        
        switch ($type)
        {            
            case 'css':
            {
                return '<link rel="stylesheet" type="text/css" href="'.$source.'.'.$type.'" '.$attrib.' />'."\n";
            }
            case 'js':
            {
                return ''."\n";
            }
            case 'img':
            {
                return '<img src="'.$source.'" '.$attrib.' />'."\n";
            }
        }
    }

Useage in View

Code:
&lt;?php echo asset('css', 'css/stylesheet', 'media="screen"'); //relative URL ?&gt;

&lt;?php echo asset('img', 'images/logo.jpg', 'alt="logo"', FALSE); // full URL ?&gt;


The forum killed the javascript part of the helper? I think you get the idea though.


Messages In This Thread
Relative URLs, or Absolute URLs? - by El Forum - 01-16-2008, 06:35 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-16-2008, 06:43 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-16-2008, 06:46 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-16-2008, 09:19 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-18-2008, 04:18 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-18-2008, 04:29 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-18-2008, 05:31 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-18-2008, 08:46 PM
Relative URLs, or Absolute URLs? - by El Forum - 01-19-2008, 07:49 AM
Relative URLs, or Absolute URLs? - by El Forum - 01-19-2008, 09:31 AM
Relative URLs, or Absolute URLs? - by El Forum - 01-19-2008, 12:05 PM
Relative URLs, or Absolute URLs? - by El Forum - 02-08-2010, 06:45 AM
Relative URLs, or Absolute URLs? - by El Forum - 02-08-2010, 06:49 AM
Relative URLs, or Absolute URLs? - by El Forum - 02-08-2010, 06:54 AM
Relative URLs, or Absolute URLs? - by El Forum - 02-08-2010, 06:59 AM
Relative URLs, or Absolute URLs? - by El Forum - 02-09-2010, 12:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB