CNET News

Tip of the Moment

In Windows XP/Vista/7 click to open the 'Start' menu and in the box at the bottom type 'MSCONFIG' and press the [ENTER] key. On the screen that comes up select the 'Boot' tab (2nd from the left) and then check the box next to the words 'No GUI Boot'.  Click 'Apply' and then press 'Okay'. You have just shaved five to ten seconds off of your boot times, have a great day!

Installing and Getting Started with HerculesCore PDF Print E-mail
Written by Todd Nestor   
Thursday, 21 July 2011 03:07

 

Installing and Getting Started with HerculesCore

HerculesCore is a framework I developed that originally started when I worked for Core Logic Systems (no longer in business). My boss there had developed what he called core, and he had been planning to release it open source, when the company went out of business I started changing core into what it is today, a fairly straightforward, easy-to-use framework that allows web developers, experienced and inexperienced alike to program faster and more efficiently. There is very little of the original framework left other than the “using” function, but we’ll get to that later.

First thing you need to do is download HerculesCore. Next unzip it and place core in the folder you are going to use it in.

Your folder hierarchy should be something like this:

/website <- this folder should have your php documents that are going to use HerculesCore (including the few examples included)

/website/minicore should be the minicore folder that you unzipped and it includes the folders /_conf and /_core among other things

Hopefully you understand what I mean

If you are going to use any of the database functionality from HerculesCore then you are going to first need to go into the config file and set some variables. If not then skip this next part:

Go into the minicore folder and then into _conf

Open the file config.php

There are three variables near the top to be adjusted:

$cfg['DATABASE']['password'] = 'database_name';

$cfg['DATABASE']['password'] = 'user';

$cfg['DATABASE']['password'] = 'pass';

 

Replace database_name with the name of your database, user with your username to login to the database, and pass with the password for that database

Now we are ready to move on.

Open the included file template.php that should be in the same folder that the minicore folder is in.

This is the basic layout for every page that uses core, the very top will always look like:

<?php

//require prepend file

require('minicore/_conf/conf.php');

You will call for class families next, basically you will call for the folder.subfolder.subfolder, etc

Ex: we want to use the otherHTML class located in minicore/_core/System/htmlcode/, we always start from the _core folder, so we need to call for System.htmlcode like this:

using(‘System.htmlcode’);

This makes all those classes in that folder available for use, you can call for as many different folders as you want (note calling for a folder does not include its subfolders) so if we also need the commonLists class in the system folder then our code for including all the files we need will look like this:

using(‘System’);

using(‘System.htmlcode’);

And yes, it is case-sensitive. Next you of course need to make instances of classes before you can use them, so if you are unfamiliar with OOP in PHP here is an example to use the two classes we already mentioned:

$commonLists = new commonLists();

$html = new otherHTML();

And then everything below that is your code, in a minute I’ll walk you through a simple page to show you how to use some of HerculesCore’s built in functions.

After all your code we have the:

require('minicore/_conf/append.php');

line that displays various data in comments so if you look at the page source in a browser you’ll see how long it took to execute the script, some session variables if you’re using sessions, etc, this line is in fact optional, and HerculesCore works just fine without it.

 

Alright, now for the second part of this tutorial, open up the initialTutorial.php file located in the same folder as minicore. I’m going to walk you through this file line by line, well sort of

It starts out:

<?php

//require prepend file

require('minicore/_conf/conf.php');

 

//Call for necessary class families from minicore

using ('System');

using ('System.Forms');

using ('System.htmlcode');

 

//Create new instances of all classes used in this page

$commonLists = new commonLists(); //this is an example of how you create an instance of a class, note you must be "using" the folder that the class is in

$html = new otherHTML(); //this class has various html tags HerculesCore can write for you, the commonLists shows you oddly enough, commonLists

$formHTML = new form(); //this class has html form tags (such as <form> <input> <select>, etc)

$forms = new commonDropDowns(); //this class has various commonly used dropdown menus

Of course the first few lines are just initiating core and calling for the folders that we will need (System, System/Forms and System/htmlcode). Then we created instances of the four classes we use throughout this page.

We are making a simple form that submits data to itself and displays it with a link to go back so our next code:

///all your code goes below

if($_POST['name'])

{

echo "<pre>";

print_r($_POST);

echo "</pre>";

$html->a(1,"Go Back",$_SERVER['PHP_SELF']);

}

else

{

Simply displays the posted data if a name was entered before the form was submitted, echo “<pre>” and “</pre>” simply make it so the browser displays the data in between in an unformatted format.

print_r is a function built into php to print out arrays completely, so we just simply print the $_POST array so we can see everything that was submitted.

The next line $html-> a(1,"Go Back",$_SERVER['PHP_SELF']); creates a link to the page itself (thus clearing out any submitted data and displaying the form again). This is a function built into HerculesCore’s otherHTML class, if you recall we set $html to be an instance of this class. The 1 echoes the <a> tag, a 0 would simlpy return the value and you would have to set it to a variable or echo it out, the “Go Back” is the display text for the link, and the next argument is the link page, in this case this page itself.

Ok so then the else just says that if no name was submitted we’re going to display the form, that is what the next code creates, I’ll walk you through this part line by line because it is mostly HerculesCore proprietary functions.

$formHTML->form(1,1,$_SERVER['PHP_SELF'],'testForm');

Recall that $formHTML is an instance of the form class, the form() function being called for here creates a tag <form enctype='multipart/form-data' name='testForm' id='testForm' method='post' action='/core_demo/initialTutorial.php'>, the first ‘1’ is saying to echo the tag to the page, if this was set to 0 it would not echo it and so you could set the tag to a variable and echo it at a different time or location. The second 1 is saying this is an opening <form> tag, if it were a 0 it would create a </form>, the third variable $_SERVER[‘PHP_SELF’] is saying to submit the page to itself, you could set this to any document you want to handle the form data, including other websites., the ‘testForm’ just sets the name of the form. The other variables are all kept as there default, the next one would be the target (used to target a new window, or a frame), this is set to 0, after that you could choose ‘post’ or ‘get’ for the method.

Our next line:

$formHTML->textbox(1,'name',"","","","Name: ");

Calls for the textbox function also in the form class. This creates a textbox, again the first 1 echoes it, a 0 would make it simply return the data, the second ‘name’ sets the name of the text box to ‘name’, the next three arguments are left blank, they are value, id and other (in that order). Value sets the default text of the box, id sets the id=”” value for the text box, other lets you add other HTML to the textbox so you could put “class=’someclassname’” and it would take the attributes set by CSS to that class.

The next line simply writes a * after the textbox.

After that we have: $html->br(1,2); which you’ll see several times. It writes out the <br /> tag, the 1 echoes it, a 0 would return it instead, the 2 is actually telling it how many to write out, so we are writing out <br /><br />, you can put any number greater than 0 here.

Next we are simply writing “I am this cool:” followed by another <br /> tag (by default its set to only write out 1 <br /> tag).

Next we have:

echo $forms->numbersDrop('write',1,20,'coolness');

This function doesn’t have an echo function so we preceed it with echo to write out the returned string to the browser. $forms is an instance of the commonDropDowns class which includes several different dropdown menus. The numbersDrop simply creates a dropdown of numbers, the first argument set to ‘write’ can also be ‘Digit’ which would make it show a ‘1’ instead of ‘One’, the next argument is the starting value, which can be any number as long as its smaller than the next argument which is the ending value. and then the final argument sets the name of the dropdown menu to ‘coolness’.

You can run this page and look at the source code created to get a better understanding of what it is doing.

Next we echo out two more <br /> tags and then Gender: then another <br />.

The next line creates a gender dropdown box for Male/Female, the first argument would set the name, by default it is set to genderArray, so you may want to change that just by making it genderDrop(‘newname’) where ‘newname’ is whatever name you give it.

Next we echo two more <br /> tags followed by:

echo $forms->countriesDrop('country','title',1, 0,'US');

which creates a drop down menu of all the countries. The first variable sets the title of the dropdown box. You can set the second variable to ‘title’, ‘both’ or ‘val’, title makes it display the country name, val just the abbreviation, and both displays both. The next value sets whether categories of options titles will be displayed, doesn’t apply to countries, it would apply to states as in (states, provinces). And the fourth option set to 0 can be set to 1 to disable the element, you’d want to do that if you have some javascript code that enables it for instance. The fifth argument sets the initial value, you but the acronym for the country in here so ‘US’ means ‘United States of America’ is initially selected.

Next we echo two more <br /> tags followed by creating a little array. This array is just to show you how to make a custom dropdown box with HerculesCore, so we gave the array three values and a title. Any element you set to "__TITLE__" for the id makes it a title, you can see the difference if you look at the page in a browser. This is where you might play with displaying category titles or not. The next three values are home, business, and other, and their display text.

Then we created the dropdown box with this code: $formHTML->select(1,$anArray,'address_type','lab'); where the first argument echoes it (a 0 would just return the value, not display it), the second argument passes the array we created to the function, the third argument sets the title, the fourth chooses to display just the label (Home Address instead of home). The next argument, left blank would set the CSS class of the box (“classname”), and then the next argument which is set to 0 could disable the box if set to 1, and the final argument would choose the default selection. So if we wanted to make it CSS class ‘banana’ disabled and have ‘other’ chosen by default it would look like this:

$formHTML->select(1,$anArray,'address_type','lab',’banana’,1,’other’);

The next code creates a textarea, the first argument echoes it, the second sets the default text and the third sets the name, the fourth sets the width in pixels, the fifth the height, the sixth could turn off the word wrap if set to ‘off’ and the last is just other attributes to be included i.e. “class=\’aclassname\’”.

Alright then we do more <br /> tags, echo out *Required, more <br /> and then we create a submit button. It echoes by default, that is the first argument, set to 0 to return instead of echo, second value is the name, next would be the value “Go for it” would display that text on the button, next would be the CSS id, and finally would be the other attributes like “class=\’aclassname\’”.

The next line creates the </form> tag, 1 to echo it and 0 to make it a closing tag.

The next line close out the else {} statement, and then we require the append file and close the page.

That should be it. Love you guys! Ha ha jk J

 

Last Updated on Thursday, 21 July 2011 03:22