Welcome Guest, Not a member yet? Register   Sign In
Direct echo in Controller - bad parctice?

Many thanks. Short, to the point and very helpful. Chris.

(04-03-2015, 03:56 PM)CroNiX Wrote: I use a templating system that I've built that includes an asset manager so you can inject css/js/meta tags, etc, into the head of the document from the controller. But in short:

 //load jquery
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript" charset="utf-8"></script>

 //load stuff from the controller
 <?=$head; ?>


//load a js file
$data['head'] = '<script src="/js/somejs.js" type="text/javascript" charset="utf-8"></script>';
//set a js var!!
$data['head'] .= '<script type="text/javascript">var variable ="hello";</script>';
//load some css!!
$data['head'] .= '<style type="text/css">@import url("/css/main.css");</style>';

$this->load->view('your_view', $data);

Messages In This Thread
RE: Direct echo in Controller - bad parctice? - by ChrisRitson - 04-04-2015, 03:02 PM

Theme © iAndrew 2016 - Forum software by © MyBB