Can I add admin links with dynamic JavaScript from my controller in CodeIgniter 2? -


i want cache of controllers’ output, of pages need have links can add , edit info. if set “js” controller , routed “global.js” “global” method of “js” controller, couldn’t use php dynamically add javascript “global.js” if i’m logged in admin? there better way cache pages if visitor not admin?

i want show add/edit/delete links on page, if i'm logged in admin. want cache page. codeigniter's caching doesn't support conditional caching, needed workaround insert links dynamically. i'm using php dynamically write javascript can use jquery insert links.

1) set in /config/routes.php:

$route['js/global.js'] = 'js/global_scripts'; // function can't called "global" since it's php keyword 

2) have function in js controller:

public function global_scripts() {     $this->output->set_header("content-type: application/x-javascript")     $this->load->view('js/global'); // see below } // global_scripts 

3) , js/global view:

$(document).ready(function(){     <?php if($this->is_admin == true): ?> // auth + my_controller     alert("you're admin"); // or whatever js want     <?php endif; ?> }); 

in view files have regular javascript link:

<script src="/js/global.js"></script> 

if visit page , i'm logged in admin, alert, , don't alert if i'm not logged in admin. can have script insert add/edit/delete links if i'm logged in.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -