0

I have written the following codes for my view, javascript and controller.

Whenever a user clicks on the delete button in the view, it will call the function named "remove_image". Then, the image name (fullpath) will be passed over to the delete_banner (controller).

The value of fullpath is dynamic it can be in the following format "assets/images/banner3.jpg" and "banner4.jpg".

Th problem I am facing is that, when the fullpath is "assets/images/banner3.jpg" and I var_dump the value of $image_name in the delete_banner controller, it only returns "assets" instead of "assets/images/banner3.jpg".

The link written in html and php looks something like this:

<a href="<?php echo base_url().'backendBanner/delete_banner/'.$banner['banner_path']; ?>">

Code for the button in view to call the function

<td>
      <a onclick="return remove_image($(this));" rel="<?php echo $banner['banner_path']; ?>"><input type="button" class="btn btn-danger" value="Delete"></a>
</td>

Code for the function In this function, $banner['banner_path'] is equal to fullpath

<script>
            function remove_image(img)
            {
                if(confirm('<?php echo lang('confirm_remove_image');?>'))
                {
                    var fullpath  = img.attr('rel');
                    alert(fullpath);
                    window.location="<?php echo base_url().'backendBanner/delete_banner/'; ?>" + fullpath;
                }
            }
        </script>

Controller

public function delete_banner($image_name)
    {
        var_dump($image_name);
    }
1

1 Answer 1

0

You must use ajax for call a controller from view

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.