base_url of Codeigniter 3 by changing the call link of css and js

Asked

Viewed 2,921 times

2

Good afternoon, folks! I’m making a website with a signup page that uses codeigniter and bootstrap, but I’m having a problem:

CSS and JS load normally, but when I make a signup and redirect a page to display a success message, all CSS and JS are no longer called in the right place and the page defaults.

Ex.: the css file should be loaded through the following link:

"h ttp://localhost/test/Assets/css/inscription.css"

but when redirecting is done, it happens to be called on the following link:

"http://localhost/test/inscription/Assets/css/inscription.css"

That is, it is no longer called in the correct place. And where it appeared "/inscription/ ", in the middle of the link, in the call of the file, just out of the blue?

I am using the base_url() function, which is configured as follows:

    $config['base_url'] = 'http://localhost/teste/';

In html:

    <link href="<?php base_url(); ?>assets/css/inscricao.css" rel="stylesheet">

DETAIL: if in html I take base_url(); and in place put directly "http://localhost/test/", this problem will not happen.

OBS: this redirection I do is through Codeigniter’s URI Routing.

Controller code:

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

    class Inscricao extends CI_Controller {

        public function index($indice=null)
        {
            $this->load->view('estrutura/header');
            $this->load->view('estrutura/menu');

            if($indice==1){
                $this->load->view('estrutura/msg_sucesso');
            } else if($indice==2){
                $this->load->view('estrutura/msg_erro');
            }

            $this->load->view('inscricao');
            $this->load->view('estrutura/footer');
        }

            public function inscrever(){
                $data['nome'] = $this->input->post('nome');
                $data['email'] = $this->input->post('email');

               if($this->db->insert('alunos',$data)){
                      redirect('inscricao/1');
               } else{
                   redirect('inscricao/2');
               }
           }
    }

In the file "Routes.php", it looks like this:

    $route['inscricao/(:num)'] = 'inscricao/index/$1';

Someone who can help me, please? What’s wrong? From now on, I thank anyone who can help! = D

1 answer

2


Hello, try this on:

$config['base_url'] = '';

or

$config['base_url'] = 'http://localhost'

and place an echo in base_url:
echo base_url('Assets/css/inscription.css');

  • Hi! I made the changes and now it is working. I am very grateful, because it helped me a lot! See you! ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.