Showing posts with label tutorials. Show all posts
Showing posts with label tutorials. Show all posts

Thursday, April 10, 2008

Objects in Javascript

Javascript does not use a standard class model. It uses objects that are like associative array structures of data, or so I have read. Regardless of how it works, you can make a class-ish type construct in Javascript.

I'll try to go over the basics here to help anyone who is interested.

Objects are defined by creating a new function. Inside the function you can define variables and methods that are attached to the primary function. The primary function is really like the constructor for the object as well.

For example:


function ObjectExample(constructorParameter1, constructorParameter2)
{
//define a variable and assign a constructor value to it
this.variable1 = constructorParameter1;
this.variable2 = constructorParameter2;

//you can also define variables with var, but they act differently
var variable3 = this; //assigns an instance pointer to a "constructor" variable

//defines a function that is attached to the object
//this function has one parameter
//pretend that this.variable1 is a reference to a div element
this.statusIndicator = function(statusText)
{
//make sure an element reference was returned before trying to set properties
if(this.variable1 != null)
{
document.getElementById(this.variable1).innerHTML = statusText;
}
}

//you can also have a function with zero parameters
this.aBoringFunction = function()
{
alert('YO!');
}

//you can call an instance function from inside the "constructor" (aka. primary function)
this.aBoringFunction(); //every time an instance is created we will get a pop-up
}



To use the object we just defined we would do something like this:

//create a new instance
var newObjectInstance = ObjectExample('7', divReference);

//execute a object function
newObjectInstance.statusIndicator('Hello...');




That's about it, let me know if I missed something, or there was an error. I typed the code out rather then copying something I know works for readability reasons.

Friday, August 10, 2007

Drupal: CMS Migration To A Server

I've been modifying Drupal (drupal.org) for a neighborhood organization website. It took a little research as, like most similar open-source projects, the documentation leaves something to be desired. I now have the site to a point where I want to put it up on the Internet. I have some hosting, so I got the domain... and bam, it's on the web right? Well no.

I feel it is necessary to make a general process overview as it took a good deal of research and tweaking to get it working:
-I have "reseller hosting." That means I can host multiple domains with the space/bandwidth that comes with the yearly fee. I bought the neighborhood domain, added a special hosting plan (defines storage, bandwidth, and other properties), and tried configuring the dns information

-Seeing as I have not done too much with the whole domainname-dns-nameserver-whatever configuration process I had some trouble figuring it out. What I ended up doing was having my domain name registrar create 2 name servers from the IPs that link to the hosting server(s). Then I used the hosting's name servers as well. ns1.site.com, ns2.site.com, ns1.hosting.com, ns2.hosting.com... all being able to process the name translation. On the hosting side for "editing DNS Zones" I set it up with ns1.nameservice.com as NS records, the IP as and 'A' record, the www as a cname for site.com.... etc. Most of the data was preconfigured by cPanel, but for some reason I had to change a few things from the defaults to get it working properly. This whole aspect will take a lot more research to understand fully.

-Copy by hand or install Drupal from cPanel (assuming your host uses cPanel)

-If you are developing on a windows machine, make sure you reconfigure your temporary directory from c:\windows\temp to /tmp. Drupal will most likely make a folder for you. I didn't do this the first time and it made a crappy "c:\windows\www" folder on the server that was a pain to remove.

-Login into your local mysqladmin (assuming you use that to manage your sql databases) and make a backup of your local Drupal database. I had to set the compatibility to an earlier version of mysql. For some reason at the default options for the export would not work.

-If you installed from cPanel, drop all of the tables in the pre-created Drupal database before you import the backup file. Otherwise, create a sql user and database for Drupal (make sure to add the user to the database access list). Configure the settings.php file in the Drupal files to reflect the database information (there is a connection string in the php file).

-Copy over any themes or modules that you added to your local Drupal install. I didn't bother with the hassle that is the sites directory... Just put the modules and theme into the standard directory instead.

-Configure your www-root .htaccess file on the server to reflect things like url rewriting, default page (index.php), and standardizing the site path (only allowing www.site.com, not site.com or vice versa). More specifically the properties DirectoryIndex, RewriteEngine, RewriteCond, and RewriteRule

Thursday, January 11, 2007

Getting a Symfony development enviroment running on windows

Nothing is ever easy... Anyways, to get a computer ready to start developing with the Symfony PHP framework you have a few options. You can take the long, long route and install apache, php, and a database server. With that you have to do a good deal of configuration to get everything working together. You could also download WAMP or XAMPP, which are just prepackaged versions. I haven't used XAMPP, so I can't say how you would get that working.

The best reason for using WAMP is that it is self contained in c:\wamp folder by default. You can also start and stop all of the server processes (Apache & MySQL) anytime by just closing the tray icon. It's great so you don't have unnecessary processes running all of the time.

The main problem is that WAMP and Symfony don't work "out of the box." No surprise there.



This is the process I used to get WAMP working with Symfony:
Download WAMP (1.6.6) and install:
http://www.wampserver.com/en/


Open a browser to http://localhost/
WAMP should display it's default webpage with links to phpmyadmin and etc.
If you are going to use MySQL it might be a good idea to change its root account to have a password. You can use phpmyadmin to do that, just click the link to it on the WAMP localhost page.

There will be a problem once you change the password. Phpmyadmin won't be able to reconnect to MySQL until you edit this file:
C:\wamp\phpmyadmin\config.inc.php:
Search for this line below in the file and put your password between the '':
$cfg['Servers'][$i]['password'] = '';


Extract the Symfony Sandbox to c:\wamp\www for testing later:
http://www.symfony-project.com/get/sf_sandbox.tgz
If that link doesn't work, just go to http://www.symfony-project.com/ and checkout the download page.

Read this tutorial for some needed info:
http://www.symfony-project.com/trac/wiki/SymfonyOnWAMP

It basically said to:
Open c:\wamp\Apache2\bin\php.ini
Search for and remove the comment symbol ';', change 'On' to 'Off', or just edit the lines to be the same as these below.
extension=php_xsl.dll
magic_quotes_gpc = Off
register_globals = Off
include_path = ".;c:\php\includes;c:\wamp\php\pear"


The magic_quotes_gpc and register_globals parts were not in the tutorial, but WERE NECESSARY for me to change. I was getting a 500 internal server error before I set those values to Off.


Install PEAR for PHP (taken from that Wiki article directly):
1. Start -> Run -> cmd
2. Cd into the PHP directory (e.g. C:\wamp\php)
3. Invoke go-pear.bat. Follow through the options (default should work fine).
If you have a problem when running the bat file like "Warning: Cannot use a scalar value as an array," in php 5.2.0 the file was broken for windows. You can check out this website for more info. You can just download the new version of the file from svn here.


Open C:\wamp\Apache2\conf
Remove the comment character '#' from this line:
LoadModule rewrite_module modules/mod_rewrite.so


Point a browser to http://localhost/sf_sandbox/web/
You should get a page that says something like:
Congratulations!
If you see this page, it means that the creation of your symfony project on this system was successful....



A few more notes to get the Symfony sandbox example working:
http://www.symfony-project.com/tutorial/my_first_project.html
Edit symfony.bat in the sf_sandbox folder that you extracted to c:\wamp\www
Change the line:
set PHP_COMMAND=php.exe
to
set PHP_COMMAND=c:\wamp\php\php.exe

I'm still having some problems with the example, but it is *kind of* working so far. I had to edit both php.ini files with all of the previous modifications.

Sunday, January 7, 2007

Learning asp.net visually

Microsoft has a great site with video tutorials here. They cover various aspects of visual web developer in VB and C#. They can't cover topics in too much detail, but more then enough to be worth while. Plus they are free....