Web Tool Bag  
Home · Articles · Downloads · Discussion Forum · Web Links · News CategoriesFebruary 05 2012 10:57:15
Navigation
Home
Articles
Downloads
Discussion Forum
Web Links
News Categories
Search
Users Online
Guests Online: 2
No Members Online

Registered Members: 625
Newest Member: nownigcheencex43
Forum Threads
Newest Threads
reverse mortgage
Science channels in ...
How can I see the fu...
Order Flagyl Without...
X-Rumer 7.0 - best s...
Hottest Threads
Installation [11]
Hermoine nude [6]
Captcha picture d... [6]
Integrate with Vi... [5]
Any questions and... [5]
Trusted web hosting

Coupon Code
WEBTOOLBAG
Latest Articles
jQuery Accordion - m...
Few Guidelines for W...
Move OST to PST to U...
Microsoft OST vs. Mi...
Tips for Specialized...
Gallery 2 Module Development: Database part 1
While making this tutorial i will talk about creating tables. I will talk about the rest in another tutorial, this tutorial alone is already quite some text.

Before I will start with explaining how to make a database, there is something you really should know. There are 2 ways of making a database. First, the a bit more difficult but good way. Second, the easy but wrong way.

The good way: Make!
The right way is by using a file called gnumakefile to make the DB files. You need to make a .xml file where you tell the gnumakefile file what fields you want in your table. When you've made the xml file, you need to run “make” or “gmake” in the folder where gnumakefile is located. (there are some needed details about this, i will write about that in a minute) Then gnumakefile is called by make (or gmake), and two files are made. An .INC file, and a .TPL file. (which will be located in a new folder that's also newly made)

The filename of the .inc file depends about the type of storage you are using, a map or an entity. You can read what the difference is in my first tutorial. (Click) When you want a map type of table, the file will be called Maps.inc. (notice the capital M) And an entity type of table will be named Entities.inc. (again with the capital E)

The .tpl file will be stored in a new folder called GalleryStorage. The tpl itself is called schema.tpl.

When you activate a new module, g2 will search the schema.tpl file, and reads the data in the file.. Followed by creating a brand new custom table!

So, lets stop our little chit chat and make ourself a custom table!

I will talk about making a Map type table in this tutorial, making a entity shouldn't be much different.

The files for the database are stored in a new folder. So go over to your module folder, and create a new folder called classes. (ex. /modules/mymodule/classes) Then make a new .xml file called Maps.xml.

The xml file look a bit like this:

Code:

1
<!DOCTYPE maps SYSTEM "../../../lib/tools/dtd/MapsDefinition2.0.dtd">
2
<maps>
3
  <map>
4
    <map-name>ModuleNameMap</map-name>
5
    <schema>
6
      <schema-major>1</schema-major>
7
      <schema-minor>0</schema-minor>
8
    </schema>
9
    <member>
10
      <member-name>itemId</member-name>
11
      <member-type>INTEGER</member-type>
12
      <primary/>
13
    </member>
14
    <member>
15
      <member-name>stringStorage</member-name>
16
      <member-type>STRING</member-type>
17
      <member-size>MEDIUM</member-size>
18
      <required/>
19
    </member>
20
  </map>
21
</maps>


I think this would make sense right?

- <map-name>ModuleNameMap</map-name> Defines your table name.
- <member>...</member> Defines a new field.
- <member-name>itemId</member-name> Defines a field name.
- <member-type>INTEGER</member-type> Defines the type of field.
- <member-size>MEDIUM</member-size> Defines the size of the field.


Save the file, and run gnumakefile in the /modules/mymodule/classes folder. You can get gnumakefile from from the /modules/comment/classes module. Or download it from Combined-Minds.net. (the version that came with 2.1 development edition.. if this version doesn't work with the current version of g2, please reply to this tutorial)

If this worked, upload the new files to your server and install/activate the module. And the database is build.

Ah, and now some of you got a problem right? Your using Windows and don't have make or gmake? Well there are some things you can do..

- Download cygwin, a linux emulator to still be able to use linux stuff on windows
- Run the make file on the server by using SSH
- Being a bad boy and go over to the wrong side of this tutorial


You are still reading this tutorial? Ah, so you've chosen to do it the wrong way?

The bad way: Create the files yourself!
Today (22-feb-07) i had a kind of discussion with on of the main developers of the g2 project. We were talking about how creating a table in g2. I told him that i make tables by using the technique that i will explain in a few minutes. He actually became a bit irritated when i said i would write a tutorial, and talk about the wrong way of making a table.

The reason why this way is wrong, is because you don't know if the files you will create will work on all servers. And the way of making the files with the make file won't change, but the way i will talk about in a minute will probably change in a few g2 versions. (don't worry, i will update the tutorial)

So, only use the following way if the good way doesn't work.

The bad technique is writing the 2 files needed yourself. It's not difficult at all, so lets start at looking at an example.

Maps.inc

Code:

1
<?php
2
$mapInfo
['ModuleNameMap'] = array(
3
    
'itemId'=>array(
4
       
'type'=>STORAGE_TYPE_INTEGER,
5
       
'size'=>STORAGE_SIZE_MEDIUM,
6
       
'notNull'=>true),
7
    
'stringStorage'=>array(
8
       
'type'=>STORAGE_TYPE_STRING,
9
       
'size'=>STORAGE_SIZE_MEDIUM,
10
       
'notNull'=>true)
11
    
);
12
?>



This basically is the same as the Maps.xml shown before. But written on a different way.

schema.tpl (remember that this file should be located in a new folder named GalleryStorage)

Code:

1
## mysql
2
#  ModuleNameMap
3
CREATE TABLE DB_TABLE_PREFIXModuleNameMap (
4
 DB_COLUMN_PREFIXitemId int(11) NOT NULL,
5
 DB_COLUMN_PREFIX stringStorage  varchar(128) NOT NULL
6
) TYPE=DB_TABLE_TYPE
7
/*!40100 DEFAULT CHARACTER SET utf8 */;
8

9
INSERT INTO DB_TABLE_PREFIXSchema (
10
 DB_COLUMN_PREFIXname,
11
 DB_COLUMN_PREFIXmajor,
12
 DB_COLUMN_PREFIXminor
13
) VALUES('PersoonNaamMap', 1, 0);


Again very simple, plain SQL. But notice DB_COLUMN_PREFIX. This is just a define that contains the prefix for the database. You are already working at a wrong way, so you can remove DB_COLUMN_PREFIX and add the prefix yourself if you want.

When you're done, save the files and upload it to your g2 installation. Install, or reactivate your module, and the table should be made!

Again please remember this way isn't like its meant. Always try to use the make file way!

http://www.combined-minds.net

Posted by zdravko on December 10 2007 15:48:30 2 Comments · 1146 Reads · Print
Comments
Emilya on September 30 2011 05:48:51
fake rolex boxes cartier pasha cheap rolex watches and youthful femininity and fills the air with allure. A pink concept is excellent for outside spring or summer time weddings. rolex replica In case you are in search of pink bridesmaid gowns, you could possibly be most delighted to understand that there's a wonderful range of fantastic bridesmaid dresses in pink that will undoubtedly go nicely with bridesmaid of pretty much all skin tone breitling superocean fakes . inexpensive b2 bridesmaid dresses on sale fake omega watches : Chocolate Bridesmaid Gown Satin Strapless Straight Neckline Taffeta Or Satin Strapless Straight Neckline With Asymmetrical Choose Up A Line Floor Duration Skirt In Stylish Waistband Decoartion Very hot Provide Orange Or Pink And Chocolate Bridesmaid Gown BM 0275 Typically, blond and honest skinned females appear amazing in
Emilya on October 17 2011 07:34:45
unexpectedly decides he desires to sit down. As we deal with the sea and start to really feel our bare ft curl deliciously inside the awesome sand christian louboutin official site , he starts to inform me that he bought some thing tiny for my birthday but which the larger present awaited me in Ny. I responded by declaring, aaww, you did not need to get something for me sweetie, cheap ballet pumps wanted brand boots this journey was sufficient.a As he caresses my encounter along with his tender arms, he starts to specific his adore for me. At this time, I did not understand what to feel. The setting along with the mood was so surreal,Permanently Yours, that I felt as though I used to be sedated and taken to paradise. As we carry on to embrace one another, he abruptly sit's up, reaches into his pocket, pulls out the box, will get on 1 knee and asks me the magic query christian louboutin flats . Following rapidly selecting up my mouth that quickly dropped onto his lap, red pump I maintained to say sure! Are you able to think
Post Comment
Please Login to Post a Comment.
Ratings
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Login
Username

Password



Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Member Poll
Which PHP framework do you preffer?

Symfony

Zend

PHPDevShell

PHP on TRAX

eZ Components

Fusebox

PhpOpenbiz

Prado

QPHP

Seagull

You must login to vote.
Shoutbox
You must login to post a message.

Vince
03/10/2011 18:17
Hi, How to remove Register from Login screen? I don't want them to register and have full access! if you leave register then they should not have any rights until the admin assigns them

webtoolz
26/09/2011 08:28
Please describe your problem with more details. Thank you.

bimmer98
22/11/2010 18:31
Help. There was a problem with the request; error regarding feedbackzdr form program

PHP Obfuscator
Copyright © 2012 - www.webtoolbag.com