blob: cc94848145aab813371771786532122d16cfcbb3 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3<head>
4
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<title>Scaffolding : CodeIgniter User Guide</title>
7
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
11<script type="text/javascript" src="../nav/nav.js"></script>
12<script type="text/javascript" src="../nav/prototype.lite.js"></script>
13<script type="text/javascript" src="../nav/moo.fx.js"></script>
14<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
15
16<meta http-equiv='expires' content='-1' />
17<meta http-equiv= 'pragma' content='no-cache' />
18<meta name='robots' content='all' />
19<meta name='author' content='ExpressionEngine Dev Team' />
20<meta name='description' content='CodeIgniter User Guide' />
21
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_darker.jpg" width="154" height="43" 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>
31<td><h1>CodeIgniter User Guide Version 1.7</h1></td>
32<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
33</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">
43<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
44<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
45Scaffolding
46</td>
47<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>
48</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
60<p>CodeIgniter's Scaffolding feature provides a fast and very convenient way to add, edit, or delete information in your database
61during development.</p>
62
63<p class="important"><strong>Very Important:</strong> Scaffolding is intended for development use only. It provides very little
64security other than a "secret" word, so anyone who has access to your CodeIgniter site can potentially edit or delete your information.
65If 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
73database management tool like phpMyAdmin. With CodeIgniter's scaffolding feature you can quickly add some data using its browser
74interface. 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
93a working one available. It also assumes you have configured CodeIgniter to auto-connect to your <a href="../database/index.html">database</a>.
94If 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 />
107&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<samp>$this->load->scaffolding(</samp><kbd>'table_name'</kbd>);<br />
108&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
114<p>Once you've initialized scaffolding, you will access it with this URL prototype:</p>
115
116<code>example.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>example.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>
138Previous Topic:&nbsp;&nbsp;<a href="common_functions.html">Common Functions</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
139<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;
141Next Topic:&nbsp;&nbsp;<a href="routing.html">URI Routing</a></p>
142<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>
143</div>
144
145</body>
adminb0dd10f2006-08-25 17:25:49 +0000146</html>