planning and designing part 2
Posted by: apalachee in Site Matters, tags: database, designing, developer, developing, file structure, help, mysql, php, project, templatingOk, so here we are again. If you have not read the first article then you might et a little lost so its best to read that article first.
So now we have put our plan together. and we have a basic idea of what we want and what those things should do.
So we now need to make a few decisions - we asked some of these questions in part one, but now its time to make your final decision.
- How are we going to set this up? - When i mean how are we going to set this up i mean, will we be doing this entire program raw or are there classes or functions or maybe part full scripts we can use to help achieve what we want.
- Will we be using a templating system such as smarty?
- What other languages will you be using?
Ok so those three questions are crucial. The very first step I do after this is I open Microsoft word and save it as “My Site - Database Breakdown ” and then open another new document and save it as “My site - Functions and classes breakdown”
These two files I will be using, printing, referencing, scribbling and printing some more through the entire stage. I do this for a couple of reasons
1. I can easily track what functions I have made and what variables are required for those functions
2. I also do this, because I can then well document this software once Im done. all the hard work has already been done.
The database breakdown looks a little something like this:
user_tbl {
- userid
- username
- password (md5)<– I add notes in brackets)
- email (strlower)
- level (the level of authorization this user has)
- fname (first name)
- lname (last name)
- valid (if not verified, should have validation code)
Ok so above you can see a basic break down of what one of my tables in my database will have. Those are the field names and any notes I made. I do this for all the databases i think i will need before I create the databases. This helps save time, because otherwise I have to keep going back and editing the table structure.
I also print my document, so I can see what the table fields are and easily implement it to my code.
The functions and classes breakdown document that i create looks a little like this:
user_funcs.php
loginuser($username, $password); - //This logins the user and created
logoutuser(); // Unsets all sessions for this user
getuserid($username); //gets the userid for the user in this session, so i can use it with other functions such as the one below.
getemail($userid);
So basically this is where i add the classes and functions i create for my script and I print them so i have them at hand. Obviously when I am starting a script I dont know all the functions I am going to create , so both these files will be continually edited and more info will added to them while developing.
But when I am starting a script and I have a basic idea of what I need, there are certain functions I create such as:
- We need to connect to a database so - dbconnect($dbhost,$dbun, $dbpass);
- We need to select a database so - dbselect($dbname);
- If I am using user interaction I need them to register, login, etc so register($username, $password, $email, $ip); or chkuser($username, $email);
So those functions you know you are going to use can go straight into your document. You may even have a library of already set functions like i do, that you can incorporate into your files.
Now when i started this article I asked you those three questions, because this is the stage i begin to create folders and some php files.
I know I know… I can hear you all screaming “Finally a php file”. Yes I know you are all eager to get to the actual scripting.
Well I create my folders in my local server. (By the when I create my sofgtware I do it all on a local server on my computer so I can test and check for errors and make sure it is all functional before uploading to a remote server. A great little server software is Xampp it has Apache, mysql, etc supports php, pear etc - But make sure you update it often so you can keep up with your remote server software. Also keep in mind that Xampp does have features missing and Cant do everything your remote server does. Also if the Php.ini is different from the remote and local you are going to have different effects, problems etc)
My usual folder system goes something like :
- Local server>>
- css
- images
- js
- include
- template
Ok those are my basic folders. It will get more complex as you progress on your script.
So a quick run through :
CSS: Well obviously my style sheets go in there.
Images: Well another obvious one. my Images go in there. If dealing with many images try and add sub folders such as Images> Nav; Images>banners; images>template;
JS: I tend to use Jquery quite a bit, I love the effects and applications you can create with it. So all my jquery and js files go in there.
Include: Files such as functions, classes i tend to put in there. But i structure them in a way that is less confusing. eg:
include>classes; or include>lib; include>configs; or include>settings;
Template: Here is where I place my template folders. I love using template folders, because often I like to change one part of the template and I dont wish to do it over and over and over .But again i put my little sub folder system into play there as well, such as:
template > forms;
Now this will change if you are using smarty. Generally with smarty you put it all in one template folder or you can divide your template folder depending on themes eg: template>silverbluetheme; or template>yellowandblacktheme;
Smarty also has a great caching system, so if you are using smarty you will also need to create template_c folder in your root(local server folder).
I know this all sounds complex if you are starting out, but if you are going to learn you should try and learn all the good habits of developing and not learn the unorganized way and go file hunting when you are looking for something.
Before we go on to php, Make sure you protect those folders from robots and prying eyes. I will explain a little more below.
Ok now to the PHP:
The files I generally create with any software is : (if highlighted in red, it means it is a name of the folder.)
- config.php or settings.php
- globals.php
- css/index.php - //This will stop people being able to access your css root and seeing files in that folder
- js/index.php - //This will stop people being able to access your js root and seeing files in that folder
- images/index.php - //This will stop people being able to access your images root and seeing files in that folder
- template/index.php - //This will stop people being able to access your template root and seeing files in that folder
- include/index.php - //This will stop people being able to access your incude root and seeing files in that folder
- include/chk.php or include/foo.php or include/whatever.php // This is a file I create to check whether this person is trying to access this file directly or is it being included . If it is being access directly it will give them an error.
- index.php
- .htaccess //Set permissions for directories and set error pages that will be created later. Also tell the root that my default file is index.php in most cases this wont be neccesary but I have come accross some servers that have default.php or home.php as their default.
- robots.txt // Deny robots from certain directories such as your, css, js, images, include, template folders
Ok so there are a few files that I can create immediately, Because with any project I know I am going to require those folders.
In the next article I will discuss a templating system I have created that does not use smarty.
Please share any of the systems or file structures you use, Id love to see what other developers do.
Well thanks and till next time >> Smile a while
Go ahead get over there now..





Entries (RSS)