Monday, February 7, 2022

[FIXED] Codeigniter base_url not working when deleting, adding and updating the data

Issue

I am making a codeigniter program that can Add, Edit, Delete, Update and View the data in the database. The logical error here is that the base_url is not working at all. When I click the delete, add and update button it goes to the about:blank page.

     <table cellspacing="0" cellpadding="2" border="1" width="50%">
            <tr>
                <th>S.No</th>
                <th>Name</th><th>Email</th><th>Address</th>
                <th>phone</th><th>&nbsp;</th><th>&nbsp;</th>
            </tr>

            <?php

                $i=1;
                foreach($query as $row)
                {
                ?>
                    <tr>
                        <td><?php echo $i; ?></td>
                        <td><?php echo $row->name; ?></td>
                        <td><?php echo $row->email; ?></td>
                        <td><?php echo $row->address; ?></td>
                        <td><?php echo $row->phone; ?></td>
                        <td><a href="<?php echo base_url().'/index.php/emp/update/'.$row->id; ?>">Edit</a></td>
                        <td><a href="<?php echo base_url().'/index.php/emp/delete/'.$row->id; ?>">Delete</a></td>
                    </tr>
                <?php
                    $i++;
                }
                ?>

                <tr><td colspan="7"><a href="<?php echo base_url(); ?>/index.php/emp/add_new">Add New</a></td></tr>
        </table>

Solution

If you want to used base_url. First step, You must have to URL helper loaded in your application/config/autoload.php

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

Or you can load URL Helper Manually by

$this->load->helper('url');

Then You can call base_url like

echo base_url();

But Remember One thing,

If this base_url is not set in your config.php file then CodeIgniter will get the protocol, domain and path to your installation.

But If you are define base_url in your application/config/config.php then base_url is loaded from here.



Answered By - hardik solanki

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.