Jamie Fearon
Jamie Fearon

Reputation: 2634

Getting assets in Codeigniter giving error.

Im trying to get up an asset helper in Codeigniter. I have created the following file in application/helpers:

asset_helper.php

<?php

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

?>

I then inport this helper into my controller like so:

$this->load->helper('asset');

When I want to use an asses in my 'html' I do the following:

<link href="<?=asset_url()?>/css/bootstrap.css" rel="stylesheet" media="screen">

My directory structure is:

application
system
assets
-- js
-- imgs
-- css

When my program is run I get the following error:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /Applications/XAMPP/xamppfiles/htdocs/editor/application/controllers/pages.php on line 5

Where line 5 is where I try to call asset_url() like so: /css/bootstrap.css" rel="stylesheet" media="screen">

Where am I going wrong, all my code seams to be correct.

Upvotes: 0

Views: 483

Answers (2)

Nish
Nish

Reputation: 1137

Here is an asset helper for CodeIgniter. Also the asset helper having a feature to merge files into one file when the names are passed in array. So will help to reduce the number of HTTP requests in your website.

http://www.thephpcode.com/blog/view/css-and-javascript-asset-helper-for-codeigniter.html

Upvotes: 0

tomexsans
tomexsans

Reputation: 4527

function asset_url(){
   $CI =& get_instance();
   $ci->load->helper('url');
   return $ci->base_url().'assets/';
}

You have to get the instance of CI in order to load or use core functions on the helper

Upvotes: 2

Related Questions