CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code
Generate PHP Code
After installing StarUML PHP 5 Code Generator Template , StarUML will have a capability to generate PHP template code based on the models we have defined before. But there’s a little hack to be done so that the naming of the file generated complies with CodeIgniter.
These PHP template code files can be used to simplify our jobs by not typing all class’ attributes and methods that we have done in the UML design and analysis phase.
Now open and edit the template file for PHP 5 code generation, located at “C:\Program Files\StarUML\modules\staruml-generator\templates\PHP 5 Code Generator\template.cot”. Locate at around line 327:
remove the .class extension and change it to
Save the file. After editing the above line, PHP template file generated will have .php extension and not .class.php extension which is not suitable to be copied to CodeIgniter file structure.
Next we will generate the PHP template code. Open the UML diagram file. Click on “Tools – StarUML Generator..” menu.
A new dialog will be shown where we can choose a template for code generation.
On the dialog, choose PHP 5 Code Generator. Click Next. A new dialog will be shown where we can choose the destination folder to save the generated files.
On the dialog, choose any folder you wish. Then click Next. A new dialog will be shown showing that the generation process is ready to run.
Click on Generate button to start the generation process. Wait a moment until the process is finished. When it was finished, we will have some PHP files that each related to our model and controller class diagram before.
After generating both model and controller template files, we can see them on the destination folder specified before, for example, mine is on “c:\temp” folder.
Next, we need to move or copy all model files to CodeIgniter “models” folder and all controller classes to CodeIgniter “controllers” folder. If you followed the instruction exactly as in this tutorial, the it would be at “C:\xampp\htdocs\acct\system\application” folder where you could find “models” and “controllers” folder inside.
Let’s take a look for the generated PHP template file for a model, for example Bankbook_model.php file:
class Bankbook_model extends Model {
public $idbankbook;
public function get() {
return;
}
public function getAll() {
return;
}
public function addNew() {
return;
}
public function addDetails() {
return;
}
public function getDetails() {
return;
}
public function sumTotal() {
return;
}
public function getNewNumber() {
return;
}
public function delete() {
return;
}
public function posting() {
return;
}
public function update() {
return;
}
public function deleteDetails() {
return;
}
public function updateDetails() {
return;
}
}
?>
As you can see, we already have a template for our CodeIgniter model that’s ready for us to code the scripts logic inside. It has all the attributes and methods exactly the same as we designed in the UML diagram.
As in the model class’ template, we could also see the controller class’ template. Let’s take a look at the Bankbook.php file for example which is for Bankbook controller class.
class Bankbook extends Controller {
public function Bankbook() {
return;
}
public function index() {
return;
}
public function addNew() {
return;
}
public function editForm() {
return;
}
public function save() {
return;
}
public function delete() {
return;
}
public function viewReport() {
return;
}
public function addDetail() {
return;
}
}
?>
Again we can see that we already have all attributes and methods exactly the same as defined in the UML diagram.
Edit config.php
Next, we need to edit our CodeIgniter configuration file to suit our application environment. Open and edit the file “system/application/config/config.php” and locate the line of:
Change and modify the content of base_url configuration to your own server name, for example http://localhost/ . Don’t forget to put a trailing forward slash (/) on it. This will be the reference of other CodeIgniter’s class for your server base URL, ie. for calling other web resources on your application like other controller, images, JavaScript files, CSS, etc.
Edit database.php
Next, we need to configure our database connectivity parameters to be used by the application. Open and edit the file “system/application/config/database.php” and locate these lines and adjust the parameters to suit your own MySQL database settings:
$db[‘default’][‘username’] = "root";
$db[‘default’][‘password’] = "";
$db[‘default’][‘database’] = "acctdb";
$db[‘default’][‘dbdriver’] = "mysql";
Edit routes.php
Next, we need to configure the default controller for our application. By default, this controller is called “welcome” and we can find the corresponding controller class file in “system/application/controller/welcome.php”. We need to change it to our main page called “Mainpage.php”.
Open and edit the file “system/application/config/routes.php” and change the default_controller parameter like this.
At this point you should be able to access your controller class from browser even though it still do nothing but a blank page.
In this case, a blank page is all right, because we have not defined anything inside the controller methods (index() method in this case). Compare this to access an undefined controller class, for example ‘bank’ controller, that will result a Page not Found error message like this:
Try to access other controller classes like cashbook, coa, mainpage, etc. All of them should return a blank page and not any error messages.
In the next step, we will start to code the logics inside each controller and model classes’ methods based on the specification and user requirement.



Yeah!!
I’ve been waiting for this!
Thank you :)
thanks to all readers… it gives me spirit to write more.
regards
I want to know, how to make the documentation that we type on StarUML also generated on code documentation? will you also send the reply to my email address. thanks ìn advance
Hi
here’s what StarUML can do in generating documentation:
- design assesment document (DAS)
- design review document
- use case specification document
all can be accessed from the tools – StarUML generator…
on thier website, i found some other plugin for generating other kind of output, please consult them
Where is the rest?? hope it will come very soon…..
Hi, I was trying to follow along, but the routes stuff does not work – first of all, shouldn’t it be called “Mainpage”, instead of “Main”? Second, whatever I put in there, I get a 404 error (created by CodeIgniter); I tried all controllers (Cashbook, Coa, Journal, Mainpage and Bankbook) – none of them work.
@tkhobbes
Yes you’re right , it should be Mainpage instead of Main, i have edited the post, Thanks a lot.
Error 404 means that the controller we are accessing is not exists. If you are using Linux, please recheck the filename case (it’s case sensitive).
@Yoosuf
So far, it has been 4 parts. Next part is on going. Thanks a lot
This is really, i mean really great.
Thank you so far for sharing your knowledge.
The presentation is outstanding and never seen before in such a detailed way.
Lookin forward to the next parts!
The filename case was the problem – the staruml application generated files with first letter in capitals
Nice… dari kemaren nyari2 website yang bisa dengan gamblang (dan sederhana) menjelaskan sedikit analysis dan design pake CI menggunakan UML. Ternyata… oh ternyata… mantap bos!
Sejauh ini, sudah cukup buat saya untuk bisa memulai project. Tapi tetep ditunggu loh lanjutannya, siapa tau ada tips and trick yang bagus lagi.
Thanks :)
Where is the next ? Isn’t published..
Btw.. Very Nice Tutorial…
Thanks..it’s great!! step by step. It’s very good newbie. Lookin forward to the next parts. :)
Hi
Thanks for the info it is great. I have been checking your site for updates for quite a while. When can we expect the next instalment?
Gracias por el aporte.. esperamos la siguiente parte, thank you
keren tutorialnya.
Sudah baca dari 1 – 4, Lanjutannya ditungguu…
very nice, thank’s :)
Very nice tutorial, I’m ansious for the next part of it :D
Lanjut gan …
ditunggu part – part selanjutnya ..
Hi, i just want to inform you that this tutorial is so great ,i am going to be checking this site for the update for as long as it take ,thanks a bunch for sharing your knowlegde and hope you will share more of your knowlegde ….Thank you very much.
I can’t say anything. Amaze… Looking forward to see u’r next tutorial bro…
what an amazing approach. great tuts, but i having some problem when generating, there was an eror encountered that tells
“error occurs for executing document translator. Reason : Class not registered”
“Access violation at address 03300CBD in module ‘GENERA~1.DLL’. Read of address 00000038.”
can you help me with this? email me pls. thanks
I hope you finish this series. This is very interesting so far.
Hello, This is a great tutorial and I love it. When will Part 5 be released? I really want to learn codeigniter.
Thanks.
mantep gan… baru sekarang nih ngeliat tutorial yang ampe class diagram de el el dibagi filenya ma prog indo, teruskan berkarya gan… hehehe… ane ijin sedot ya gan… :D ;-).
Sukse selalu gan…. entar kalo ane dah ngerti itu UMLan tak trackback sekalian yak…
only one word to say…. Mantabs
This tut has shown me new ways of doing things. I really do enjoyed it. The problem is that the suspends is taken so long. I am aware of the time that goes into preparing this kind of tutorials. But hope you deliver.
@fcolondam
hi, i have the same problem are resolved??
tanks for your help.
nice article mas,,lanjut ya…ta simak tutornya…
It is great for me. But I appear Object not found Error 404, I change all folder and file name to lower case still appear this case. I use win7 pro. and xmapp, have you any idea for my situation. Thx