Its my first project using CodeIgniter and it is not as easy as it seems.
I have to import different JSs and CSSs in different pages and I'm stuck.
First of all, I've seen that hardcoding echos are not CI way of doing it so I made a simple class like
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Fileload {
public function loadjs($filename)
{
echo '<script language="javascript" type="text/javascript" src="'.$filename.'"></script>';
}
public function loadcss($filename)
{
echo '<link rel="stylesheet" type="text/css" href="'.$filename.'" >';
}
}
?>
And in my controller I used it like
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->library('fileload');
$this->load->view('head');
$this->load->view('mainpage');
$this->fileload->loadjs('//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.min.js');
$this->load->view('tail');
}
}
But the slick library supposed to be at the bottom right above the 'tail' is at the top inside of head> tag, which is inside view('head');
It seems that the controllers' methods are not running in the sequence I've wrote it down. It should've echoed the script file first.
Can anybody explain how this CodeIgniter controller works??