Welcome Guest, Not a member yet? Register   Sign In
Anchor setup wih a php echo
#1

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!!

Heart Heart ,
Mekaboo
Reply
#2

(This post was last modified: 07-08-2019, 01:38 AM by neuron.)

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', 
array(
'title' => 'The best news!',
'class' => 'btn btn-warning',
'onclick' => 'return confirm('Are you sure to delete data?')?true:false;'
)
); 
 
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
Reply
#3

(This post was last modified: 07-08-2019, 06:17 AM by Wouter60.)

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.
Reply
#4

(07-08-2019, 01:35 AM)neuron Wrote: 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', 
array(
'title' => 'The best news!',
'class' => 'btn btn-warning',
'onclick' => 'return confirm('Are you sure to delete data?')?true:false;'
)
); 
 
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

Thank you so very much Heart
Reply
#5

(07-08-2019, 05:32 AM)Wouter60 Wrote: 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.
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 Sad
Reply




Theme © iAndrew 2016 - Forum software by © MyBB