blob: 18e0dadad61e88091966e4e55f621969455752dc [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>
Derek Jonesbbedc762009-09-11 14:47:37 +000031<td><h1>CodeIgniter User Guide Version 1.7.2</h1></td>
Derek Allard2067d1a2008-11-13 22:59:24 +000032<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
Derek Allard03d0a572009-02-04 12:57:50 +000060<p class="important">Scaffolding has been deprecated from CodeIgniter as of 1.6.0.</p>
61
Derek Allard2067d1a2008-11-13 22:59:24 +000062<p>CodeIgniter's Scaffolding feature provides a fast and very convenient way to add, edit, or delete information in your database
63during development.</p>
64
65<p class="important"><strong>Very Important:</strong> Scaffolding is intended for development use only. It provides very little
66security other than a "secret" word, so anyone who has access to your CodeIgniter site can potentially edit or delete your information.
67If you use scaffolding make sure you disable it immediately after you are through using it. DO NOT leave it enabled on a live site.
68And please, set a secret word before you use it.</p>
69
Derek Allard2067d1a2008-11-13 22:59:24 +000070<h2>Why would someone use scaffolding?</h2>
71
72<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
73into it to work with. Without scaffolding your choices are either to write some inserts using the command line or to use a
74database management tool like phpMyAdmin. With CodeIgniter's scaffolding feature you can quickly add some data using its browser
75interface. And when you are through using the data you can easily delete it.</p>
76
77<h2>Setting a Secret Word</h2>
78
79<p>Before enabling scaffolding please take a moment to set a secret word. This word, when encountered in your URL,
80will launch the scaffolding interface, so please pick something obscure that no one is likely to guess.</p>
81
82<p>To set a secret word, open your <kbd>application/config/routes.php</kbd> file and look for this item:</p>
83
84<code>$route['scaffolding_trigger'] = '';</code>
85
86<p>Once you've found it add your own unique word.</p>
87
88<p class="important"><strong>Note:</strong> The scaffolding word can <strong>not</strong> start with an underscore.</p>
89
90
91<h2>Enabling Scaffolding</h2>
92
93<p>Note: The information on this page assumes you already know how <a href="controllers.html">controllers</a> work, and that you have
94a working one available. It also assumes you have configured CodeIgniter to auto-connect to your <a href="../database/index.html">database</a>.
95If not, the information here won't be very relevant, so you are encouraged to go through those sections first.
96Lastly, it assumes you understand what a class constructor is. If not, read the last section of the <a href="controllers.html">controllers</a>
97page.</p>
98
99<p>To enable scaffolding you will initialize it in your constructor like this:</p>
100
101<code>
102&lt;?php<br />
103class Blog extends Controller {<br />
104<br />
105&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function Blog()<br />
106&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
107&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parent::Controller();<br /><br />
108&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<samp>$this->load->scaffolding(</samp><kbd>'table_name'</kbd>);<br />
109&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
110}<br />
111?&gt;</code>
112
113<p>Where <kbd>table_name</kbd> is the name of the table (table, not database) you wish to work with.</p>
114
115<p>Once you've initialized scaffolding, you will access it with this URL prototype:</p>
116
117<code>example.com/index.php/<var>class</var>/<dfn>secret_word</dfn>/</code>
118
119<p>For example, using a controller named <var>Blog</var>, and <dfn>abracadabra</dfn> as the secret word,
120you would access scaffolding like this:</p>
121
122<code>example.com/index.php/<var>blog</var>/<dfn>abracadabra</dfn>/</code>
123
124<p>The scaffolding interface should be self-explanatory. You can add, edit or delete records.</p>
125
126
127<h2>A Final Note:</h2>
128
129<p>The scaffolding feature will only work with tables that contain a primary key, as this is information is needed to perform the various
130database functions.</p>
131
132
133</div>
134<!-- END CONTENT -->
135
136
137<div id="footer">
138<p>
139Previous Topic:&nbsp;&nbsp;<a href="common_functions.html">Common Functions</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
140<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
141<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
142Next Topic:&nbsp;&nbsp;<a href="routing.html">URI Routing</a></p>
Derek Jonesfc395a12009-04-22 14:15:09 +0000143<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006-2009 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
Derek Allard2067d1a2008-11-13 22:59:24 +0000144</div>
145
146</body>
adminb0dd10f2006-08-25 17:25:49 +0000147</html>