1

I have separate config js file which is included in header.

<script type="text/javascript" src="<?php echo base_url();?>assets/js/config.js.php"></script>

In this file I keep all config js variables that are need in later js. A file looks like this:

var CONFIG = (function() {                  
     var private = {
         'IMAGE_DIR': 'example1',
         'UPLOAD_IMAGE_LANG': 'Upload photo',
         'BASE_URL':'',
         'USER_UPLOAD_URL':''

     };

     return {
        get: function(name) { return private[name]; }
    };
})();

The problem I have is how to pass values from php CI config constants to this file so I won't need to type the same config values in two places.

tnx

1

3 Answers 3

1

You would load that dynamic JS from your controller via a view.

Something like this

https://stackoverflow.com/a/10110790/876117

Sign up to request clarification or add additional context in comments.

Comments

0

CodeIgniter's sessions will give you all the information you can think of. If you do this...

<?php
 echo "<pre>";
 print_r($this->session);
 echo "</pre>";
?>

it will display a TON of information. Here is a sample of the output when I run it.

[config] => CI_Config Object
(
    [config] => Array
        (
                [base_url] => http://localhost/test/root/
                [index_page] => 
                [uri_protocol] => AUTO
                [url_suffix] => 
                [language] => english
                [charset] => UTF-8
                [enable_hooks] => 
                [subclass_prefix] => MY_
                [permitted_uri_chars] => a-z 0-9~%.:_\-
                [allow_get_array] => 1
                [enable_query_strings] => 
                [controller_trigger] => c
                [function_trigger] => m

this is only like 1% of the data that it outputs. You should be able to find the data you want in there and then reference it like you would with any array. You can see "base_url" is in there. Read more about CodeIgniter's sessions here

Comments

0

I would use plain PHP:

<?php require_once('../../application/config/your_file.php'); ?>

...

'IMAGE_DIR': <?php echo $config['IMAGE_DIR'];?>

Simple, no requirements for anything

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.