CodeIgniter - Form: Using URL Helper



CodeIgniter Form Step By Step Tutorial - Part 15: After create table at here, we will add links for edit and delete data. We use URL Helper to build the links.

Update books_main.php (views) with following code (add line 29 & 30):

<html>
<head>
<link rel="stylesheet" type="text/css" 
      href="<?php echo "$base/$css"?>">
</head>
<body>
<div id="header">
<? $this->load->view('books_header'); ?>
</div>
<div id="menu">
<? 	$this->load->view('books_menu'); ?>
</div>
<? echo heading('List of Books',3); ?>
<table border="1">
  <tr>
    <th>ID</th>
    <th>Title</th>    
    <th>Author</th>    
    <th>Year</th>
    <th colspan="2">Action</th>        
  </tr>
<?php 
foreach($query as $row){
  echo "<tr>";
	echo "<td>". $row->id ."</td>";
	echo "<td>". $row->title ."</td>";
	echo "<td>". $row->author ."</td>";
	echo "<td>". $row->year ."</td>";
	echo "<td>". anchor('books/input/'.$row->id,'Edit') ."</td>";
	echo "<td>". anchor('books/del/'.$row->id,'Delete') ."</td>";		
  echo "</tr>";	
}
?>
</table>

<div id="footer">
<? $this->load->view('books_footer'); ?>
</div>

</body>
</html>

You can see, than write line like this

<a href="http://localhost/CodeIgniter/
index.php/books/input/1">Edit</a>
Better:
<?php echo anchor('books/input/1','Edit'); ?>
codeigniter url helper


Series this article:
CodeIgniter - Form: Creating Skeleton
CodeIgniter - Form: File Structure
CodeIgniter - Form: Creating Layout Code
CodeIgniter - Form: Creating Menu Library
CodeIgniter - Form: Putting Text at Header and Footer
CodeIgniter - Form: Centralizing $data
CodeIgniter - Form: Adding CSS
CodeIgniter - Form: Creating Form HTML
CodeIgniter - Form: Creating Beautiful Form Code
CodeIgniter - Form: CodeIgniter HTML Style
CodeIgniter - Form: Preparing Table at Database
CodeIgniter - Form: Creating Insert Data
CodeIgniter - Form: Creating List Data Use Table Library
CodeIgniter - Form: Creating Table List Without Table Library
CodeIgniter - Form: Using URL Helper
CodeIgniter - Form: Showing Single Data for Form Edit
CodeIgniter - Form: Something Happen With Form Parameters
CodeIgniter - Form: Updating Data
CodeIgniter - Form: Deleting Data


Tag: CodeIgniter, framework, MVC, URL Category: PHP Framework Post : February 28th 2008 Read: 10,463 Bookmark and Share

blog comments powered by Disqus