• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
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
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, 02: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, 06: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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.