1

in config.php , its possible to make another variable and call it in view

$root="http://".$_SERVER['HTTP_HOST'];
$root.=str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;


$config['img_url']=$root.'assets/img/';
$config['jsctrl_url']=$root.'application/JsController/';

and call it like

<script type="text/javascript" src="<?php echo jsctrl_url();?>Account/register.js"></script>

1 Answer 1

2

What you need is a constant and not a function like base_url.

Head on to your config/constants.php and create a new one like:

$root ="http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

define('IMG_URL', $root . 'assets/img/');
define('JS_URL', $root . 'application/JsController/');

Then in your views you would use it as a normal constant.

<script type="text/javascript" src="<?php echo JS_URL ?>Account/register.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.