![]() |
Anchor setup wih a php echo - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Anchor setup wih a php echo (/showthread.php?tid=74008) |
Anchor setup wih a php echo - Mekaboo - 07-07-2019 Hello! I know how do anchors in general but when it comes to links like this: <a href="addEdit.php?id=<?php echo $row['id']; ?>" class="btn btn-warning">edit</a> or <a href="postAction.php?action_type=delete&id=<?php echo $row['id']; ?>" class="btn btn-danger" onclick="return confirm('Are you sure to delete data?')?true:false;">delete</a> how do I setup the anchor so it connects correctly? I dont see an example in the CI tutorial. Thank you so very much!! ![]() ![]() Mekaboo RE: Anchor setup wih a php echo - neuron - 07-08-2019 You don't have to use CI's anchor function. Personally I don't use it. If you want to use it: PHP Code: echo anchor('news/local/123?id=' . <?php echo $row['id']; ?>, 'My News', Also avoid relative urls. (if you use anchor() function you don't have worry about it) Use in following formats: 1. "/addEdit.php" (starting with backslash) or 2. "http://www.domain.com/addEdit.php" (full URL) First one result's less code and easy to maintain than second format RE: Anchor setup wih a php echo - Wouter60 - 07-08-2019 Anchor is a CI helper function. Your question proves that your website does not follow the CI architecture. In CI, all url's are handled by index.php, so you never address php files directly, just controller classes and methods inside controllers. Anchor will include CI's site_url automatically. Example: Controller: Products Method: save_product() Argument for the method: the id of the given product. PHP Code: <?= anchor('products/save_product/' . $id, 'Save', 'class="btn btn-warning"');?> The first argument is the url. The second argument is the caption for the button (visible text). The third argument is an optional string with options. If you need an "onclick" attribute, you can include it in the string, or you can use an array. First, rebuild your application from traditional flat php to the Model-View-Controller structure that CI is using. RE: Anchor setup wih a php echo - Mekaboo - 07-08-2019 (07-08-2019, 01:35 AM)neuron Wrote: You don't have to use CI's anchor function. Thank you so very much ![]() RE: Anchor setup wih a php echo - Mekaboo - 07-08-2019 (07-08-2019, 05:32 AM)Wouter60 Wrote: Anchor is a CI helper function.I do have MVC that can push through, didn't know how to connect as far anchor. Unfortunately this was source code that caught my eye but the creator of the code don't want to give advice instead charge a boatload of money to implement ![]() |