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);
}