1

Currently I'm trying to write an AJAX script under my views folder in codeigniter. for this I have used <?= $this->section('scripts')?> to create a script inside the php file. But doing so gives me Fatal error: Call to undefined method CI_Loader::section(). Here is my full code:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>CodeIgniter MVC Basics</title> </head> <body> <form method='post' action="index"> <h1>Customer Details</h1> <input type="date" name="startDate"/> <input type="date" name="endDate"/> <select name="status"> <option>Draft</option> <option>Unpublish</option> <option>Let</option> </select> <br/><br/> <button type="button" class="alertbox" name="alertbox">alertbox</button> </form> </body> </html> <?= $this->section('scripts')?> <script> $(document).ready(function(){ $(document).on('click', '.alertbox', function(){ alert("Hello world"); }); }); </script> <?= $this->endsection()?> 

I want it so that whenever the button is clicked, there should be an alert popup in the screen.

EDIT I am loading the view from my controller like this:

$this->load->view('crm/test'); 

The following is the error:

enter image description here

3
  • How are you loading the view, I mean what does the controller look like? Commented Oct 5, 2021 at 7:48
  • @Don'tPanic could you have a look at stackoverflow.com/questions/69446003/… Commented Oct 5, 2021 at 7:54
  • I edited your question and added the relevant code - your question needs to include all the relevant info, here, not spread between other questions. Commented Oct 5, 2021 at 8:05

1 Answer 1

1

This code:

$this->load->view('crm/test'); 

is how you load a view in Codeigniter 3.

This code:

<?= $this->section('scripts')?> ... <?= $this->endsection()?> 

is using layouts, from Codeigniter 4. So it looks like you're using CI4, but as shown on that layouts page, and in the main views documentation, the way to render and display a view in CI4 is different:

echo view('crm/test'); 
Sign up to request clarification or add additional context in comments.

1 Comment

Hey, could you also checkout stackoverflow.com/questions/69450553/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.