Welcome Guest, Not a member yet? Register   Sign In
How to Configure CodeIgnitor and a Javascript Framework (Mootools)
#1

[eluser]polaris1927[/eluser]
I have a basic question.

What is the best way to configure CI to use a Javascript framework such as Mootools or jQuery???

Thanks
#2

[eluser]freshface[/eluser]
What do you mean with configure?
This is how I work: create your ownconfig file and load it in the autoload.
Load the config settings in your controller and pass this to your view.
This is my code:

Config:

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

    $config['disable_login'] = TRUE; // Warning, for debugging only!
    $config['page_title'] = 'Invoice System';
    
    // Meta
    $config['meta_description'] = "";
    $config['meta_keywords'] =  "";
    $config['meta_author'] =  "";
    $config['meta_copyright'] =  "";
    $config['meta_company'] =  "";
    $config['meta_revisit'] =  "5 days";
    
    // CSS + Javascript + Favicon
    $config['css'] =  array();
    $config['javascript'] =  array('myScript.js','mootools.js'); // Fill this
    $config['favicon'] =  'favicon.ico'; // Includes a base_url()
    

?>

Controller:

Code:
// Meta
            $data['meta_description'] = $this->config->item('meta_description');
            $data['meta_keywords'] =  $this->config->item('meta_keywords');
            $data['meta_author'] =  $this->config->item('meta_author');
            $data['meta_copyright'] =  $this->config->item('meta_copyright');
            $data['meta_company'] =  $this->config->item('meta_company');
            $data['meta_revisit'] =  $this->config->item('meta_revisit');
            // CSS + Javascript + Favicon
            $data['css'] =  $this->config->item('css');
            $data['javascript'] =  $this->config->item('javascript'); // You can extend the array here if you want to load some more javascript
            $data['favicon'] =  $this->config->item('favicon');
            $data['page_title'] =  $this->config->item('page_title');
    $this->load->view('page/layout', $data);

View:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;

&lt;!-- Meta --&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;meta http-equiv="imagetoolbar" content="no" /&gt;
&lt;meta name="description" content="&lt;?php echo $meta_description ?&gt;" /&gt;
&lt;meta name="keywords" content="&lt;?php echo $meta_keywords ?&gt;" /&gt;
&lt;meta name="author" content="&lt;?php echo $meta_author ?&gt;" /&gt;
&lt;meta name="copyright" content="&lt;?php echo $meta_copyright ?&gt;" /&gt;
&lt;meta name="company" content="&lt;?php echo $meta_company ?&gt;" /&gt;
&lt;meta name="revisit-after" content="&lt;?php echo $meta_revisit ?&gt;" /&gt;

&lt;!-- CSS --&gt;
&lt;?php
    foreach ($css as $i => $value){ echo '&lt;link rel="stylesheet" href="' . base_url() . $css[$i] . '" type="text/css" media="screen" /&gt;'; echo "\n";}
?&gt;
&lt;!-- Javascript --&gt;
&lt;?php
    foreach ($javascript as $i => $value){ echo ''; echo "\n";}
?&gt;
&lt;!-- Favicon --&gt;
&lt;?php
    if(isset($favicon)){ echo '&lt;link rel="icon" href="' . base_url() . $favicon . '" type="image/x-icon" /&gt;'; }
?&gt;

&lt;title&gt;&lt;?php echo $page_title ?&gt;&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;


&lt;?php
    if(isset($feedback_error)){ echo $feedback_error; }
    if(isset($feedback_success)){ echo $feedback_success; }
?&gt;

&lt;!-- Menu --&gt;
&lt;?php if(isset($menu)){ echo $menu; } ?&gt;
&lt;!-- // Menu --&gt;

&lt;!-- Log out (if available) --&gt;
&lt;?php if(isset($logout)){ echo $logout; } ?&gt;
&lt;!-- // Log out  --&gt;

&lt;!-- Content --&gt;
&lt;?php if(isset($body)){ echo $body; } ?&gt;
&lt;!-- // Content --&gt;

&lt;/body&gt;
&lt;/html&gt;
#3

[eluser]freshface[/eluser]
The forum stripped out the javascript tags in the view so you need to put them in yourself.




Theme © iAndrew 2016 - Forum software by © MyBB