Organizational Research By

Surprising Reserch Topic

using external js with php extension in codeigniter


using external js with php extension in codeigniter  using -'php,javascript,codeigniter,fatal-error'

I am using codeigniter 2 and I have my theme folder consist of js, img, css folders.

Inside js folder, file name is js_functions.php contains:

<?php header("Content-type: text/javascript"); ?>
/**
 * GLOBAL VARIABLES & PATHS
 *
 * path definitions for jquery inline usage
 *
 */     
var base_url         = '<?=base_url();?>';
// ------------------------------------------------------------------------

/**
 * jquery.message Global Implementation
 *
 * Shows message if any session flashdata named message is set
 *
 */

<?php if($this->session->flashdata('message')):?>
$(function() { $().message("<?=$this->session->flashdata('message');?>"); });
<?php endif; ?>

// ------------------------------------------------------------------------


and, calling in it view file

<script type="text/javascript" src="<?=base_url();?>themes/admin/js/js_functions.php"></script>


renders correctly. But it returns in the chrome's inspect screen:

var base_url         = '<br />
Uncaught SyntaxError: Unexpected token ILLEGAL


and in the browser when you call the page from address bar:

var base_url         = '<br />
<b>Fatal error</b>:  Call to undefined function base_url() in <b>F:\xampp\htdocs\themes\js\js_functions.php</b> on line <b>11</b><br />


What's wrong? Isn't it the correct way of using php in external js/php file?
    

asked Sep 15, 2015 by ErickGallowa
0 votes
11 views



Related Hot Questions

3 Answers

0 votes
NULL
answered Sep 15, 2015 by AlyLonon
0 votes
NULL
answered Sep 15, 2015 by DenMcDonagh
0 votes
NULL
answered Sep 15, 2015 by LatoyaNolenq

...