Getting started
In this tutorial I’ll show you how to install, what to watch to start using iScaffold 2.0. This article assumes that you have basic understanding of how CodeIgniter works.
First, you need to know what is iScaffold and what it isn’t, so you wouldn’t expect things that this project isn’t mend to cover.
Use it to:
To generate a CRUD application that efficiently provides an interface for managing you database.
Create data models for your applications data manipulation.
Manage automated coding tasks.
Step 1: getting and installing iScaffold
The first step is that you download the package from our downloads page.
- Unpack it to the location you prefer
- Open system\application\config\config.php and set base_url
- Open system\application\config\database.php and set it to your database that you wish to manage with the generated code.
- Make the /output directory writable, set it to 777
- Point you browser to the installation directory and if all goes well, you should see a big green line, saying: “The output directory is writable, have fun using iScaffold”
Step 2: creating the application environment
You will need a different place to run the generated source code so download a copy of CodeIgniter (1.7.2 at this time) or create an environment that can handle your new application.
Step 3: desinging and creating you database
This is the most important step, not just in iScaffold, but in many fileds of web development. iScaffold works by analyzing your database schema and creating the application based on that. Let’s see it:
- Set a field to NULL if you want to skip validation and make it NOT required, otherwise it’s always mandatory to fill in all the forms.
- Watch the fields length. Form validation will not accept more characters, than you set in your schema.
- If you want to create a one to many relationship between tables, you have to create a switch table. This will be discussed later in detail.
- You are able to manage enum values in a HTML select list, so get use of this.
- If you want checkboxes on your application set the field to int(1)
- For file upload support, set the field to varchar(36)
- Date are automatically converted from human readable format to UNIX timestamp, so if you want dates to be handled, set your timestamp field to int(10) and the app converts the rest.
- TIP: It’s a good idea to give your fields a prefix. Example: table name is “posts” than name the fields to p_id, p_title, p_desc, p_timestamp. This will help you recognise where a field belongs to. If you have a “products” table also than use the prefix “pr_” instead of “p_” again.
Designing a good database is a challenging task and with iScaffold you have the ability to spend more time on it.
I think this step will be discussed in much more details in the future, but these simple guidelines should be enough to move along.
Step 4: configuring your database schema
Point your browser to the iScaffold installation and click on “Configure table data”. If your database didn’t have an “sf_config” table, than the configurator creates it for you, to store the settings you make for a database field.
The configurator also populates the config table with the fields of your database schema.
Open the grey lines and make your settings. The description line is showed as a tooltip when the user focuses on a certain input filed of the generated form.
Notes:
- The WYSIWYG option only adds a class=“wysiwyg” attribute to the textarea element. I didn’t wanted to choose an editor instead of you so that you can integrate your favorite one.
- Adding one to many relations: press the Add many relation button at the bottom of the field list. The Field id row should be an unique name in your database give it a name like it was a real table field. The Label row works like the regular ones.
- The switch table: as the configurator tells you create a table01_table02 table with the columns: table01_id, table02_id where the app will store the relations.
Note that you can rearrange the order of the fields, by dragging the cross icon on the top left of each field block.
After you finished your settings, push the “Save schema config” button on the bottom of the page.
Step 5: generating the code
After the configurator finished saving your data, you will be redirected back to the iScaffold main page, where your only task is to press the Generate button :)
Step 6: deploy the generated code
- Take the code from the /output directory and copy it on your application directory of your development environment I wrote about in step 2.
- There is a /scaffold_package directory in the root of iScaffold, copy the contents of this to the root of the development environment. These are the images, styles, libraries used by the generated application.
- Make sure that you add the iscaffold directory exception in your .htaccess file
- By default iScaffold uses Template lite (a fast Smarty replacement) as a template engine so set the application/compiled directory to writable.
- Edit /application/language/english/db_fields_lang.php in your development environment to name enum values if you wish to.
Step 7: test your application
The last point is also very important, because this is where the incompleteness of your application emerges. Until you start modifying the generated code, you are in a very convenient position: you can regenerate the code as many time as you wish, but after you made any changes it can be a bit more difficult to update the the changes, so more brain than brawn.
Point your browser to one of your controllers that iScaffold generated.
Ask the following questions to yourself question before you start the modifications:
- Does my app matches the plans?
- Am I able to update, setup anything that I would like to?
- Is it sure that table relations will be strictly one to one?
- Am I using the correct input types?
- Will it be straightforward to the users of the app what each field means?
Well, this is it. It should give you an overview of what iScaffold do for you, but this is far not everything. You can modify templates on your needs: adding, removing, altering features. You will find the template variables reference in the documentation section .
Hi,
Great tool and great tutorial, im starting to learn CI. Im getting an error once a implement the generated code. the error is:
Unable to load the requested class: template
Please advice.
Posted by Elias @ Jan 7, 06:10 PM #
Ignore my previous posting :-), now im getting this error:
A PHP Error was encountered
Severity: User Error
Message: TPL: [in line 0]: syntax error: file ‘list_user’ does not exist
Filename: template_lite/class.template.php
Line Number: 923
Posted by Elias @ Jan 7, 07:10 PM #
Hello Elias,
Thank you for testing iScaffold. Do you have all the templates in the /view folder?
Do you see the frame_public.tpl file’s contents in the source?
Posted by Tibor @ Jan 7, 10:03 PM #
yup, all the tpls are in the application/view folder. The frame_public.tpl is in the view folder too and the size is 3KB. Im WAMP on Windows.
tks for helping.
Posted by Elias @ Jan 8, 03:12 PM #
This a list of errores that i get:
A PHP Error was encountered
Severity: User Error
Message: TPL: [in frame_public.tpl line 43]: syntax error: expecting ‘=’ after attribute name ‘.tpl\’ (class.compiler.php, line 638)
Filename: template_lite/class.template.php
Line Number: 923
——————————————
A PHP Error was encountered
Severity: User Error
Message: TPL: [in frame_public.tpl line 43]: syntax error: file ‘list_message’ does not exist
Filename: template_lite/class.template.php
Line Number: 923
—————————————
A PHP Error was encountered
Severity: Warning
Message: fopen(application/views/\list_message) [function.fopen]: failed to open stream: No such file or directory
Filename: template_lite/class.template.php
Line Number: 691
————————————————
A PHP Error was encountered
Severity: Warning
Message: filesize() [function.filesize]: stat failed for application/views/\list_message
Filename: template_lite/class.template.php
Line Number: 692
———————————————
A PHP Error was encountered
Severity: Warning
Message: fclose() expects parameter 1 to be resource, boolean given
Filename: template_lite/class.template.php
Line Number: 714
I really dont know whatsa the problem.
Posted by Elias @ Jan 8, 07:53 PM #
Hello Elias,
Try changing the main include in frame_public.tpl to:
{ include file=$template.”.tpl” }
Also try to remove the “/” from the end of the template_dir in libraries/template.php
It seems to me that you have a nasty path problem.
Debugging idea:
echo $this->tpl->template_dir in libraries/template.php to see where CI wants to search for templates.
Posted by Tibor Szász @ Jan 9, 02:13 PM #
Hi Tibor,
It was a Windows issue, i uploaded the same code to a linux machine and it worked instantly.
tks for the support.
Posted by Elias @ Jan 9, 02:29 PM #
I’m glad to hear that!
Posted by Tibor Szász @ Jan 9, 02:33 PM #
Whatever I do I am not able to save the labels on the table data configuration. Also, the “hidden” checkbox is disabled. Always.
Posted by Pål Oliver Kristiansen @ Jan 19, 04:04 PM #