skip to Main Content

I have written a simple view to use bootstrap css in codeignitor.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Voyager</title>
        <link rel="stylesheet" href="<?php echo base_url("styles/bootstrap/css/bootstrap.css"); ?>" />
</head>
<body>

                <div class="panel panel-heading">
                    This is Heading
                </div>
                <input type="submit" class="btn btn-primary">

    <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo  (ENVIRONMENT === 'development') ?  'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
        <script type="text/javascript" src="<?php echo base_url("styles/bootstrap/js/jquery-3.2.1.min.js"); ?>"></script>
        <script type="text/javascript" src="<?php echo base_url("styles/bootstrap/js/bootstrap.js"); ?>"></script>

</body>
</html>.

Bootstrap directory is copied in root directory of project.

This is the link I followed for integration.

http://www.kodingmadesimple.com/2014/06/integrate-twitter-bootstrap3-with-codeigniter-framework.html

While running the application I get below error.

A PHP Error was encountered

Severity: Error

Message: Call to undefined function base_url()

Filename: views/view_login.php

Line Number: 10

Backtrace:

Note: If I remove bootstrap links, page is rendered without styles.

Here is the contents of autoload.php.

I have excluded commented parts in this file.
I made changer to helper part as you said.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$autoload['packages'] = array();

$autoload['libraries'] = array();

$autoload['drivers'] = array();


$autoload['helper'] = array('url');

$autoload['config'] = array();

$autoload['language'] = array();

$autoload['model'] = array();

After this change new error I am getting is :

Unable to load the requested file: helpers/view_login_helper.php

3

Answers


  1. Add url in applicationconfigautoload.php
    In helper array

    Login or Signup to reply.
  2. Go to your config/autoload.php and, in the helpers array do:

    $autoload['helper'] = array('url');

    That should solve the problem.

    EXTRA ADVICE: It’s usually not necessary to protect a view from direct access. That’s for your classes mainly. But still you can if you want to.

    Login or Signup to reply.
  3. Or you have to load this in the controller

    Try to open your controller and load the view

    $this->load->view('name of the view');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search