2

I got some problem here, please help me if you can solve this

so, I use CodeIgniter Framework to create a website I want to use 1 controller for 2 view, but for the second view i got the error from the javascript

this is my controller

public function __construct()
{
    parent::__construct();
    $this->load->model('M_registration');
}
public function index(){
    $this->load->view('templates/V_header');
    $this->load->view('en-us/V_home');
    $this->load->view('templates/V_footer');
}

public function registration(){
    $x['prov'] = $this->M_registration->get_prov();

    $this->load->view('templates/V_header');
    $this->load->view('en-us/V_registration', $x);
    $this->load->view('templates/V_footer');
}

and for the javascript, I use another file named :java_script.php and I called the file from V_footer.php

I use this for called the javascript in the footer

<?php include 'java_script.php'?>

</body>

</html>

then what I want to do here is : I want to go to the registration page from 1 controller example : localhost/myWebsite (this is the home view/index) -> this will called the function index then I want to the registration page from this controller : localhost/myWebsite/registration

this is my javascript in java_script.php

<script src="<?= base_url('assets/')?>js/bootstrap.min.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.validate.min.js"></script>
<script src="<?= base_url('assets/')?>js/main.js"></script>
<script>
    $(document).ready(function(){
        alert('registration page');
    });
</script>

this javascript is working in index, but not working in registration

I already apply .htaccess like this :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

is there any solution for me ? Thank you before.

maybe this can help you to understand my problem here. when I use registration function in new controller, the javascript is working but when I use the function in one controller, the javascript is not working

Lin
  • 41
  • 5

2 Answers2

0

Why overly complicate things? Instead of placing an include on the views you load, it would be much cleaner to just add the contents of your java_script.php file at the bottom of your footer (I'm not talking about inlining the code on those 3-4 js files, just paste the exact code from the java_script.php) and you're set.

The overhead of loading those files on a couple views where they are not needed is minimal, you don't have to go through the hassle of including/not including the files and everything ends up being available to be used on all views should you need to

Javier Larroulet
  • 3,047
  • 3
  • 13
  • 30
0

I'm so sorry for asking useless question

I've founded the answer

I think my javascript is the problem

I added to much base_url for javascript like this

<!-- JS here -->
<script src="<?= base_url('assets/')?>js/vendor/modernizr-3.5.0.min.js"></script>
<!--     <script src="js/vendor/jquery-1.12.4.min.js"></script> -->
<script src="<?= base_url('assets/')?>js/popper.min.js"></script>
<script src="<?= base_url('assets/')?>js/bootstrap.min.js"></script>
<script src="<?= base_url('assets/')?>js/owl.carousel.min.js"></script>
<script src="<?= base_url('assets/')?>js/isotope.pkgd.min.js"></script>
<script src="<?= base_url('assets/')?>js/ajax-form.js"></script>
<script src="<?= base_url('assets/')?>js/waypoints.min.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.counterup.min.js"></script>
<script src="<?= base_url('assets/')?>js/imagesloaded.pkgd.min.js"></script>
<script src="<?= base_url('assets/')?>js/scrollIt.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.scrollUp.min.js"></script>
<script src="<?= base_url('assets/')?>js/wow.min.js"></script>
<script src="<?= base_url('assets/')?>js/nice-select.min.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.slicknav.min.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.magnific-popup.min.js"></script>
<script src="<?= base_url('assets/')?>js/plugins.js"></script>
<script src="<?= base_url('assets/')?>js/gijgo.min.js"></script>
<script src="<?= base_url('assets/')?>js/slick.min.js"></script>
<!--contact js-->
<script src="<?= base_url('assets/')?>js/contact.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.ajaxchimp.min.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.form.js"></script>
<script src="<?= base_url('assets/')?>js/jquery.validate.min.js"></script>
<script src="<?= base_url('assets/')?>js/mail-script.js"></script>

<script src="<?= base_url('assets/')?>js/main.js"></script>


<!-- Include jQuery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script>

<!-- Include jQuery Timeline Plugin -->
<script src="<?= base_url('assets/')?>js/jquery.roadmap.js" type="text/javascript"></script>

and the 2 bottom script is the problem for all. I moved that to the top and it's fine

Thank you so much for trying to solve my problem here

Lin
  • 41
  • 5