blob: 417cb1005a5989faaec5e9fee6fc934a2934fac9 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Derek Allardafd99ac2008-01-19 19:59:14 +00002<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
adminb0dd10f2006-08-25 17:25:49 +00003<head>
4
Derek Allard8039d4c2008-05-31 02:47:56 +00005<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Derek Jonesfd93d222008-05-06 15:18:50 +00006<title>Scaffolding : CodeIgniter User Guide</title>
adminb0dd10f2006-08-25 17:25:49 +00007
8<style type='text/css' media='all'>@import url('../userguide.css');</style>
9<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
10
admin17a890d2006-09-27 20:42:42 +000011<script type="text/javascript" src="../nav/nav.js"></script>
admin2296fc32006-09-27 21:07:02 +000012<script type="text/javascript" src="../nav/prototype.lite.js"></script>
admin17a890d2006-09-27 20:42:42 +000013<script type="text/javascript" src="../nav/moo.fx.js"></script>
Derek Allardb3412372007-10-25 12:15:16 +000014<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
adminb0dd10f2006-08-25 17:25:49 +000015
adminb0dd10f2006-08-25 17:25:49 +000016<meta http-equiv='expires' content='-1' />
17<meta http-equiv= 'pragma' content='no-cache' />
18<meta name='robots' content='all' />
Derek Allard3d879d52008-01-18 19:41:32 +000019<meta name='author' content='ExpressionEngine Dev Team' />
Derek Allardd2df9bc2007-04-15 17:41:17 +000020<meta name='description' content='CodeIgniter User Guide' />
adminb0dd10f2006-08-25 17:25:49 +000021
22</head>
23<body>
24
25<!-- START NAVIGATION -->
26<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
27<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
28<div id="masthead">
29<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
30<tr>
Derek Jones6b7b11f2008-05-06 16:07:27 +000031<td><h1>CodeIgniter User Guide Version 1.6.2</h1></td>
adminc0d5d522006-10-30 19:40:35 +000032<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
adminb0dd10f2006-08-25 17:25:49 +000033</tr>
34</table>
35</div>
36<!-- END NAVIGATION -->
37
38
39<!-- START BREADCRUMB -->
40<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
41<tr>
42<td id="breadcrumb">
Derek Jones7a9193a2008-01-21 18:39:20 +000043<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
adminb0dd10f2006-08-25 17:25:49 +000044<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
45Scaffolding
46</td>
Derek Allardbc030912007-06-24 18:25:29 +000047<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
adminb0dd10f2006-08-25 17:25:49 +000048</tr>
49</table>
50<!-- END BREADCRUMB -->
51
52<br clear="all" />
53
54
55<!-- START CONTENT -->
56<div id="content">
57
58<h1>Scaffolding</h1>
59
Derek Allardd2df9bc2007-04-15 17:41:17 +000060<p>CodeIgniter's Scaffolding feature provides a fast and very convenient way to add, edit, or delete information in your database
adminb0dd10f2006-08-25 17:25:49 +000061during development.</p>
62
63<p class="important"><strong>Very Important:</strong> Scaffolding is intended for development use only. It provides very little
Derek Allardd2df9bc2007-04-15 17:41:17 +000064security other than a "secret" word, so anyone who has access to your CodeIgniter site can potentially edit or delete your information.
adminb0dd10f2006-08-25 17:25:49 +000065If you use scaffolding make sure you disable it immediately after you are through using it. DO NOT leave it enabled on a live site.
66And please, set a secret word before you use it.</p>
67
68
69<h2>Why would someone use scaffolding?</h2>
70
71<p>Here's a typical scenario: You create a new database table during development and you'd like a quick way to insert some data
72into it to work with. Without scaffolding your choices are either to write some inserts using the command line or to use a
Derek Allardd2df9bc2007-04-15 17:41:17 +000073database management tool like phpMyAdmin. With CodeIgniter's scaffolding feature you can quickly add some data using its browser
adminb0dd10f2006-08-25 17:25:49 +000074interface. And when you are through using the data you can easily delete it.</p>
75
76<h2>Setting a Secret Word</h2>
77
78<p>Before enabling scaffolding please take a moment to set a secret word. This word, when encountered in your URL,
79will launch the scaffolding interface, so please pick something obscure that no one is likely to guess.</p>
80
81<p>To set a secret word, open your <kbd>application/config/routes.php</kbd> file and look for this item:</p>
82
83<code>$route['scaffolding_trigger'] = '';</code>
84
85<p>Once you've found it add your own unique word.</p>
86
87<p class="important"><strong>Note:</strong> The scaffolding word can <strong>not</strong> start with an underscore.</p>
88
89
90<h2>Enabling Scaffolding</h2>
91
92<p>Note: The information on this page assumes you already know how <a href="controllers.html">controllers</a> work, and that you have
Derek Allardd2df9bc2007-04-15 17:41:17 +000093a working one available. It also assumes you have configured CodeIgniter to auto-connect to your <a href="../database/index.html">database</a>.
adminb0dd10f2006-08-25 17:25:49 +000094If not, the information here won't be very relevant, so you are encouraged to go through those sections first.
95Lastly, it assumes you understand what a class constructor is. If not, read the last section of the <a href="controllers.html">controllers</a>
96page.</p>
97
98<p>To enable scaffolding you will initialize it in your constructor like this:</p>
99
100<code>
101&lt;?php<br />
102class Blog extends Controller {<br />
103<br />
104&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function Blog()<br />
105&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
106&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parent::Controller();<br /><br />
Derek Allardee0a7f02008-05-08 13:59:27 +0000107&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<samp>$this->load->scaffolding(</samp><kbd>'table_name'</kbd>);<br />
adminb0dd10f2006-08-25 17:25:49 +0000108&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
109}<br />
110?&gt;</code>
111
112<p>Where <kbd>table_name</kbd> is the name of the table (table, not database) you wish to work with.</p>
113
Derek Allardc6441282007-07-04 23:54:32 +0000114<p>Once you've initialized scaffolding, you will access it with this URL prototype:</p>
adminb0dd10f2006-08-25 17:25:49 +0000115
116<code>www.your-site.com/index.php/<var>class</var>/<dfn>secret_word</dfn>/</code>
117
118<p>For example, using a controller named <var>Blog</var>, and <dfn>abracadabra</dfn> as the secret word,
119you would access scaffolding like this:</p>
120
121<code>www.your-site.com/index.php/<var>blog</var>/<dfn>abracadabra</dfn>/</code>
122
123<p>The scaffolding interface should be self-explanatory. You can add, edit or delete records.</p>
124
125
126<h2>A Final Note:</h2>
127
128<p>The scaffolding feature will only work with tables that contain a primary key, as this is information is needed to perform the various
129database functions.</p>
130
131
132</div>
133<!-- END CONTENT -->
134
135
136<div id="footer">
137<p>
Derek Allardee0a7f02008-05-08 13:59:27 +0000138Previous Topic:&nbsp;&nbsp;<a href="common_functions.html">Common Functions</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
adminb0dd10f2006-08-25 17:25:49 +0000139<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
140<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
Derek Allardee0a7f02008-05-08 13:59:27 +0000141Next Topic:&nbsp;&nbsp;<a href="routing.html">URI Routing</a></p>
Derek Jones07870432008-02-13 03:49:26 +0000142<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006-2008 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
adminb0dd10f2006-08-25 17:25:49 +0000143</div>
144
145</body>
146</html>