Monday, March 17, 2008

Google Map values

Google map address provides data as follows:
$loc_id = (lat, log);

$loc_id
= '(47.718691, -122.28464)';
preg_match_all('/-?[0-9]+(?:\.[0-9]+)?/' , $loc_id, $matches);
$a = $matches[0][0];
$b = $matches[0][1];

$a and $b provides value of latitude and longitude.

Wednesday, February 27, 2008

Installing and Configuring Lampp (the simple guide)

It may not surprise you if you read the posts around here, but I am a very lazy person when it comes to configuring and installing stuff on anything other than Windows OS. I will avoid anything that involves popping open terminal and putting commands in myself, unless I’ve found them on a forum somewhere.

So, when I was searching the Ubuntu forums for how to make lampp start with Linux, I just wished that someone would post with a clear step by step guide about how to do basic stuff with lampp.

I’ve decided to create this post in the hope that anyone else trying to configure lampp on Ubuntu Linux doesn’t have to look in completely different places to find the answers they are looking for. Note: I’m installing on a clean copy of Ubuntu Linux release 7.10 “Gutsy Gibbon”, with lampp version 1.6.4.

(By the way - non Ubuntu users: you should really give Gutsy Gibbon a spin, even if you are a Windows person like me.)

Step One - Get Lampp

Get lampp. So, you’ll need a direct link to the Sourceforge.net lampp download page.
Make sure that file is downloaded to your Ubuntu desktop, or at least move it there when it’s done, or the commands I’m telling you to paste into terminal won’t find the file.

Step Two - Install It

Yes, I know there’s a perfectly good guide on the lampp site, but it isn’t exactly the same for installing it on Ubuntu. So, I’ll include the (very slightly) modified version for you to paste into terminal below.

sudo tar xvfz Desktop/xampp-linux-1.6.4.tar.gz -C /opt

That’s it. Lampp installed. (Might take a minute or two to extract it all, but it will get there)

Step Three - Starting and Testing

Still in terminal, paste:

sudo /opt/lampp/lampp start

Now you can pop open firefox, and type “localhost” into the address bar.

Note: It should most definately work, but in some cases it doesn’t. I’m afraid this article just assumes that the install went fine, you’ll have to scour the Apache Friends Network Lampp Documentation for help. Sorry :-(

Step Four - Running Lampp At Boot

Sure, if you don’t want to make it run at start-up skip to step five by all means.

So, to make lampp auto run when you boot up your computer, firstly paste the below into terminal:

sudo gedit /etc/init.d/rc.local

When the text editor opens, paste the following just below the “#! /bin/sh” line:

/opt/lampp/lampp start

After you have inserted this line, hit the “Save” button, and close the text editor.

So, now lampp will start when you boot your linux box up. At this point I would recommend trying it out, by restarting your computer.

Step Five - Security

For one thing, it is outlined in the Lamp install instructions that your installation should be secure. So, either follow the instructions on the page above, or just paste the following into terminal:

sudo /opt/lampp/lampp security

The steps are pretty straightforward, and mostly all you have to do is enter a password and hit enter.

Step Six - Fixing Stuff

I did find some problems with the normal use of lampp, mainly with the configuration of ProFTPD. For one thing connecting via FTP over my LAN took absolutely ages to connect, hanging before it had even processed my credentials. So, after looking on numerous forums, I found that it was trying to do a reverse lookup on the client’s IP address (or something like that). The way to disable it is to get on gedit and change the proftpd.conf file. So, get on terminal and paste:

sudo gedit /opt/lampp/etc/proftpd.conf

Now, paste these two lines anywhere in the document, and click save:

IdentLookups off

UseReverseDNS off

I messed about with the settings to let me have read access to the whole server, which is obviously not advised. I also changed the ftp username from “nobody” to “alan”.

Well, that’s basically it. The lampp server is now ready to be used, so have a play around with it.

Below are the screenshots that I was going to use for this post, then decided against them. (They’re showing stuff like running terminal etc)

Oh, and if you’re wondering why all of the screenshots are in 1024×768, I took them all over the VNC server (post), and I have it at that resolution so I can see both my Windows and Ubuntu desktop at the same time, so VNC doesn’t fill the whole screen.

Source

Thursday, February 07, 2008

personal

editing the environmental path

sudo gedit /etc/environment

installation of jdk in ubuntu
sudo apt-get install sun-java6-bin sun-java6-jre

http://www.cyberciti.biz/faq/howto-ubuntu-linux-install-configure-jdk-jre/

You can use either kchmviewer or gnochm or xchm. This is to view .chm files

kchmviewer from KDE:
Code:
sudo aptitude install kchmviewer
gnochm from Gnome:
Code:
sudo aptitude install gnochm
xchm:
Code:
sudo aptitude install xchm

change samba password
sudo smbpasswd -a 'myusername' meta name="GENERATOR" content="OpenOffice.org 2.2 (Linux)">

How can i change Grub Menu?

Ok. First you need to open the grub configuration file for editing. To do this, open a terminal window (I have it un Applications/Accessories, but I think it was in Applications/System tools in breezy), type 'sudo gedit /boot/grub/menu.lst', and enter your password.


All the lines with a # in beginning are comments, they are just to help you. All the important lines are those without a #. Now find a line like 'default 0'. That's where you select which OS will boot by default. You'll have to take a look at how many separate entries you have, and which one is windows. Most likely the first 2 are Ubuntu entries, and then there's memtest, and after that would be your windows. The first entry is number 0, second is 1 etc. So if windows was the 4th entry you have, change that 'default'-line to 'default 3', if it's sixth, use 'default 5'...


If you set the line to 'default saved', grub will always default to the last used entry (if the entry has a line with 'savedefault'), so after running windows your machine would boot to windows by default, and after running Ubuntu it will boot to Ubuntu by default.



sudo gedit /boot/grub/menu.lst


Check for dependencies:


sudo synaptic


NVIDIA driver

$ sudo apt-get install nvidia-glx nvidia-kernel-common

$ sudo nvidia-xconfig

Ctrl+Alt+Backspace



Install newer modesetting Intel video driver


Unfortunately the newer driver is only available from 6.10 onwards (Edgy, Feisty etc), but not in 6.06.1 (Dapper). If you have Edgy or above then you can install the newer intel video driver with:-


sudo apt-get install xserver-xorg-video-intel


Then edit your /etc/X11/xorg.conf and change the


Driver "i810"


to


Driver "intel"



reconfigure the grapchics driver


sudo dpkg-reconfigure -phigh xserver-xorg



tar xvfz xampp-linux-1.6.5a.tar.gz -C /opt



FTP CONFIGRATIONS

sudo apt-get install vsftpd



Step # 2: Configure /etc/vsftpd.conf

The default vsftpd configuration file is /etc/vsftpd.conf. You need to edit this file using text editor such as vi:
$ sudo vi /etc/vsftpd.conf

Add the following line (uncomment line) to the vsftpd configuration file:
local_enable=YES
Above config directive will allow local users to log in via ftp

If you would like to allow users to upload file, add the following to the file:
write_enable=YES

For security you may restrict local users to their home directories. Add the following to the file:
chroot_local_user=YES

Save and close the file.


sudo /etc/init.d/vsftpd restart



rar file extractor

use terminal
sudo apt-get install rar
sudo ln -fs /usr/bin/rar /usr/bin/unrar
Applications -> Accessories -> Archive Manager

or synaptic search rar install



Permission

sudo chown nirbhab -R /opt/lampp


sudo chgrp nirbhab -R /opt/lampp


sudo chmod 777 -R /opt/lampp




HOWTO: Setup easy web development environment (XAMPP) http://joeabiraad.com/linuxunix/installing-lamp-on-ubuntu-710-linuxapachemysqlphp/100

This is a how-to for setting up a web development environment easily. This guide will install the XAMPP lampp stack into /opt, setup an easy way to start it up and shut it down, and link a folder in your home directory to the webserver.

WARNING
This guide is aimed at a development environment only and should not be used as a public webserver. To setup a public webserver follow the directions on the Ubuntu wiki
https://help.ubuntu.com/community/ApacheMySQLPHP

As this is Ubuntu, all the major parts of a typical web server are included (in the main repo, or on the Ubuntu Server CD) and this is a great way to setup a server. The ubuntu developers have prepared a great web server and have made the process as seemless as possible.

But what if even the official way is still to complicated? What if you just want a quick web server for development?

Fortunately there is the XAMPP project: http://www.apachefriends.org/en/xampp.html. The XAMPP project bundles Apache, PHP4 & 5, Perl, mySQL, and a bunch of other utilities/applications into an simple package for Mac OSX, Windows, Solaris, and Linux. Obviously this HOWTO only deals with the linux version.

For those of you with already existing Apache/mySQL/php installations it installs everything into /opt so it doesn't conflict with any other installation, and it is completely setup and ready to run.

Install XAMPP

Two easy steps:

  1. Download the most recent version of XAMPP: (at time of writing 1.5.3a)
    http://prdownloads.sourceforge.net/x...ar.gz?download
    (Source URL: http://www.apachefriends.org/en/xampp-linux.html#374)

  2. Extract the archive to /opt using sudo: (make sure you are in the directory that you downloaded the archive to)

Code:

sudo tar xvfz xampp-linux-1.5.3a.tar.gz -C /opt


Start XAMPP

To start it up, open a terminal and type this:

Code:

sudo /opt/lampp/lampp start

Stop XAMPP

To stop it, open a terminal and type this:

Code:

sudo /opt/lampp/lampp stop

Additional XAMPP commands

To see additional commands, open a terminal and type this:

Code:

sudo /opt/lampp/lampp

Sweet XAMPP Control Panel



To use the sweet gtk/python control panel:

Run in a terminal:

Code:

gedit ~/.local/share/applications/xampp-control-panel.desktop

Paste the following into the open file and save and exit.

Code:

[Desktop Entry]

Comment=Start/Stop XAMPP

Name=XAMPP Control Panel

Exec=gksudo "python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py"

Icon[en_CA]=/usr/share/icons/Tango/scalable/devices/network-wired.svg

Encoding=UTF-8

Terminal=false

Name[en_CA]=XAMPP Control Panel

Comment[en_CA]=Start/Stop XAMPP

Type=Application

Icon=/usr/share/icons/Tango/scalable/devices/network-wired.svg

"XAMPP Control Panel" will show up in your applications menu under Internet. Use the Alacarte Menu Editor to move it around.

Test to see if XAMPP is running

Once XAMPP is up and running open firefox and go to: http://localhost/

You should see the XAMPP test page:



Location of files and uploading

XAMPP by default uses /opt/lampp/htdocs as the root web directory. The easiest way to start working on files is to link a folder in your home directory into this directory.
My user name is peter so I have /home/peter/public_html linked to /opt/lampp/htdocs/peter. So if I navigate to http://localhost/peter/ I get a listing of all the files/folders in that directory. (As long is there isn't a index.php/html/etc file)
To set this up, run in a terminal:

  1. Make public_html directory in home directory:

Code:

mkdir ~/public_html

  1. Link to /opt/lampp/htdocs

Code:

sudo ln -s ~/public_html /opt/lampp/htdocs/$USER

Now any files and folders you place in ~/public_html will be published to your personal webserver.

Bookmark http://localhost/username to make this easy to access.

WARNING - SECURITY
http://www.apachefriends.org/en/xampp-linux.html#381
Open holes:

  1. The MySQL administrator (root) has no password.

  2. The MySQL daemon is accessible via network.

  3. ProFTPD uses the password "lampp" for user "nobody".

  4. PhpMyAdmin is accessible via network.

  5. Examples are accessible via network.

  6. MySQL and Apache running under the same user (nobody).

This doesn't leave your whole system wide open, but someone could hack your XAMPP installation, so be wary.
To fix most of the security weaknesses open a terminal and run:

Code:

sudo /opt/lampp/lampp security




Welcome to the Linux version of XAMPP
(on x86-compatible processors)

By the way: In the past this software was called LAMPP but to avoid misconceptions we renamed it to »XAMPP for Linux«. So if you are seeking for LAMPP you're on the right track. ;)

If you encounter any problems with XAMPP please feel free to get in touch with us. This will help us to improve XAMPP and make it more useful for everybody.


Jump-off point

Pictures of XAMPP for Linux

Installation in 4 Steps

Step 1: Download
Step 2: Installation
Step 3: Start
Step 4: Test

READ ME

A matter of security (A MUST READ!)
PHP 4 or PHP 5?
Advanced start and stop parameters
What is where?
Stopping XAMPP
Uninstall


Pictures of XAMPP for Linux

As the old saying goes, a picture is worth a thousand words. Here you can take a look at some screen shots of a XAMPP installation.

Step 1: Download

Simply click on one of the links below. It's a good idea to get the latest version. :)

A complete list of downloads (older versions) is available at SourceForge.

A detailed overview over the changes and contents of all XAMPP releases is available in the RELEASE NOTES.


XAMPP for Linux 1.6.5a, 2007/12/25


Version


Size


Notice


XAMPP Linux 1.6.5a

52 MB

Apache 2.2.6, MySQL 5.0.51, PHP 5.2.5 & 4.4.7 & PEAR + SQLite 2.8.17/3.3.17 + multibyte (mbstring) support, Perl 5.8.7, ProFTPD 1.3.1, phpMyAdmin 2.11.3, OpenSSL 0.9.8e, GD 2.0.1, Freetype2 2.1.7, libjpeg 6b, libpng 1.2.12, gdbm 1.8.0, zlib 1.2.3, expat 1.2, Sablotron 1.0, libxml 2.4.26, Ming 0.3, Webalizer 2.01, pdf class 009e, ncurses 5.8, mod_perl 2.0.2, FreeTDS 0.63, gettext 0.11.5, IMAP C-Client 2004e, OpenLDAP (client) 2.3.11, mcrypt 2.5.7, mhash 0.8.18, eAccelerator 0.9.5.2, cURL 7.13.1, libxslt 1.1.8, phpSQLiteAdmin 0.2, libapreq 2.07, FPDF 1.53, XAMPP Control Panel 0.6
MD5 checsum: ca9355ef857b00068aba21ce014422af


Upgrade 1.6.4 to 1.6.5a

23 MB

Upgrade package. How to upgrade?
MD5 checksum: 9c0f4bad6a79747598d8e3aee6d03771


Upgrade 1.6.5 to 1.6.5a

0 MB

Upgrade package. How to upgrade?.
MD5 checksum: 06f121cc6ec45a1f8accf6fee8a4d6b8


Development package

27 MB

The development package contains all files you need if you want to compile other software packages for XAMPP by yourself and the Unix manual pages. Install this package like the normal XAMPP distribution:
tar xvfz xampp-linux-devel-1.6.5a.tar.gz -C /opt
MD5 checksum: 2c652233f28554463776b133563a06ef



Attention: If you download these files on a Windows system and you're running McAfee virus scanner you may get a false positive virus warning. This is a problem with McAfee and gzip-compressed files, it should be ignored.

Step 2: Installation

After downloading simply type in the following commands:

  1. Go to a Linux shell and login as the system administrator root:

su

  1. Extract the downloaded archive file to /opt:

tar xvfz xampp-linux-1.6.5a.tar.gz -C /opt

Warning: Please use only this command to install XAMPP. DON'T use any Microsoft Windows tools to extract the archive, it won't work.

Warning 2: already installed XAMPP versions get overwritten by this command.

That's all. XAMPP is now installed below the /opt/lampp directory.

Step 3: Start

To start XAMPP simply call this command:

/opt/lampp/lampp start

You should now see something like this on your screen:

Starting XAMPP 1.6.5a...
LAMPP: Starting Apache...
LAMPP: Starting MySQL...
LAMPP started.

Ready. Apache and MySQL are running.

If you get any error messages please take a look at the Linux FAQ.

Step 4: Test

OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:

http://localhost

Now you should see the start page of XAMPP containing some links to check the status of the installed software and some small programming examples.

The Instant Art example: A small PHP/GD program (since 0.9.6pre1 also a flashy PHP/Ming example, see screenshot). Thanks to Anke Arnold for her font »AnkeCalligraph«.

A matter of security (A MUST READ!)

As mentioned before, XAMPP is not meant for production use but only for developers in a development environment. The way XAMPP is configured is to be open as possible and allowing the developer anything he/she wants. For development environments this is great but in a production environment it could be fatal.

Here a list of missing security in XAMPP:

  1. The MySQL administrator (root) has no password.

  2. The MySQL daemon is accessible via network.

  3. ProFTPD uses the password "lampp" for user "nobody".

  4. PhpMyAdmin is accessible via network.

  5. Examples are accessible via network.

  6. MySQL and Apache running under the same user (nobody).

To fix most of the security weaknesses simply call the following command:

/opt/lampp/lampp security

It starts a small security check and makes your XAMPP installation more secure.

Ads

PHP 4 or PHP 5?

Because such very new versions like PHP 5 always should be handled with care we decided to include both current versions of PHP into XAMPP since version 1.4.7: PHP 5.x and PHP 4.x. If you find out your PHP application doesn't work with PHP 5 you will be able to switch back easily to PHP 4.

By the following command you can switch "back" to PHP 4.x:

/opt/lampp/lampp php4

And with the following command you can switch back to PHP 5.x:

/opt/lampp/lampp php5

If you forgot which version of PHP is in use simply use phpinfo() or call this command:

/opt/lampp/lampp phpstatus

Advanced start and stop parameters

Until version 0.9.4 /opt/lampp/lampp could only start and stop XAMPP. Since version 0.9.5 it learned a lot of new things to do.


START AND STOP PARAMETERS

Parameter

Description



start

Starts XAMPP.



stop

Stops XAMPP.



restart

Stops and starts XAMPP.



startapache

Starts only the Apache.



startssl

Starts the Apache SSL support. This command activates the SSL support permanently, e.g. if you restarts XAMPP in the future SSL will stay activated.



startmysql

Starts only the MySQL database.



startftp

Starts the ProFTPD server. Via FTP you can upload files for your web server (user "nobody", password "lampp"). This command activates the ProFTPD permanently, e.g. if you restarts XAMPP in the future FTP will stay activated.



stopapache

Stops the Apache.



stopssl

Stops the Apache SSL support. This command deactivates the SSL support permanently, e.g. if you restarts XAMPP in the future SSL will stay deactivated.



stopmysql

Stops the MySQL database.



stopftp

Stops the ProFTPD server. This command deactivates the ProFTPD permanently, e.g. if you restarts XAMPP in the future FTP will stay deactivated.



security

Starts a small security check programm.




For example: To start Apache with SSL support simply type in the following command (as root):

/opt/lampp/lampp startssl

You can also access your Apache server via SSL under https://localhost.

What is where?

What is where? A big question of our existens, here are some answers! ;)


IMPORTANT FILES AND DIRECTORIES

File/Directory

Purpose



/opt/lampp/bin/

The XAMPP commands home. /opt/lampp/bin/mysql calls for example the MySQL monitor.



/opt/lampp/htdocs/

The Apache DocumentRoot directory.



/opt/lampp/etc/httpd.conf

The Apache configuration file.



/opt/lampp/etc/my.cnf

The MySQL configuration file.



/opt/lampp/etc/php.ini

The PHP configuration file.



/opt/lampp/etc/proftpd.conf

The ProFTPD configuration file. (since 0.9.5)



/opt/lampp/phpmyadmin/config.inc.php

The phpMyAdmin configuration file.




Stopping XAMPP

To stop XAMPP simply call this command:

/opt/lampp/lampp stop

You should now see:

Stopping LAMPP 1.6.5a...
LAMPP: Stopping Apache...
LAMPP: Stopping MySQL...
LAMPP stopped.

And XAMPP for Linux is stopped.

Uninstall

To uninstall XAMPP just type in this command:

rm -rf /opt/lampp

The end.


Tuesday, February 05, 2008

Remove index.php

Backup httpd.conf file of apache, all the changes has to be done in this file.

search for "LoadModule rewrite_module modules/mod_rewrite.so" and

remove # from the "#LoadModule rewrite_module modules/mod_rewrite.so" string. Removing '#' from the above line will actually enable the rewrite module on server.

paste the following, if not there

<FilesMatch "^\.ht">

Order allow,deny

Deny from all

</FilesMatch>


paste the following, if not there

AccessFileName .htaccess

above line will use the file name to use, will rewriting.

paste the following, if not there

IndexIgnore .htaccess

above line will remove the .htaccess from the indexing service of apache

AND THE MOST IMPORTANT TASK

search for this :

<Directory />

Options FollowSymLinks

AllowOverride None

Order deny,allow

Deny from all

Satisfy all

</Directory>



and replace by :


<Directory />

Options FollowSymLinks

AllowOverride all

Order deny,allow

Deny from all

Satisfy all

</Directory>


'all' string will allow the mod_rewrite to run for all the requests coming to server.



create one .htaccess file, you won't be able create such file in windows system, so WAMP user download it from any web server. or find some other source.



and paste following in the .htaccess file.

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]


if using CI in some directory than use

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ /directory_name/index.php/$1 [L]


don't forget to restart the apache server, so that it reloads the httpd.conf file.


creating an alias(ignore these lines):
Alias /something "/www/webapps/joomla"

Friday, February 01, 2008

New Version Released

Glad to see the new version of codeigniter, i thing i was not able to understand, why scalfolding class being deprecated? many new things to study :-)
http://codeigniter.com

Sunday, January 27, 2008

database to array

This is a small idea to fasten your web application, this is a backend process, so we are not concerned with the users internet speed, but the stability of the system relies in the hand of backend server and our scripts, what if we load whole database in n number of arrays, where n is equal to number of tables. Load database to the autoload.php file.
Here is a method to create array of a table from the database.
Create one file application/libraries/MyDbArray.php
Paste the following content to it.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MyDbArray

{

public $CI;

public $db_array=array();

function __construct()

{

$this->CI=& get_instance();

$query=$this->CI->db->get('ci_content');

$this->db_array=$query->result();

}

}

?>

Controller
<?php

class dbarray extends Controller

{

function __construct()

{

parent::Controller();

$this->load->library('MyDbArray');

}

function index()

{

print_r($this->mydbarray->db_array);

}

}

?>

LAMP

Lately I’ve been using ubuntu 7.10 for all my projects/daily work.
As a web developer i should have LAMP on my machine and now i would guide you through installing it on yours.

This guide is divided into 3 steps: installing/tesing Apache, PHP and finally MySQL.

Lets start with Apache:
1. Open the terminal (we will be using it through most of my guide) from Applications > Accessories > Terminal
2. Install apache2 using apt-get by typing the following

sudo apt-get install apache2

Note that you should know the root password.
Now everything should be downloaded and installed automatically.
To start/stop apache2 write:

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop

Your www folder should be in: /var/www/

If everything is OK you should see an ordinary HTML page when you type: http://localhost in your firefox browser

Finished with Apache ? lets conquer PHP:

1. Also in terminal write:

sudo apt-get install php5 libapache2-mod-php5

or any php version you like
2. restart apache

sudo /etc/init.d/apache2 restart

This is it for PHP :D
Wanna test it ? Just create an ordinary PHP page in /var/www/ and run it.
Example:

sudo gedit /var/www/test.php

and write in it: < ?php echo "Hello World"; ?>

Now run it by typing http://localhost/test.php in firefox… You should see your ” Hello World ”

66 % is over, lets continue to installing MySQL:
1. Again and again in terminal execute:

sudo apt-get install mysql-server

2. (optional) If you are running a server you should probably bind your address by editing bind-address in /etc/mysql/my.cnf and replacing its value (127.0.0.1) by your IP address
3. set your root password (although mysql should ask you about that when installing)

mysql> SET PASSWORD FOR ‘root’@'localhost’ = PASSWORD(’xxxxxx’);

4. Try running it

mysql -uroot -pxxx

where xxx is your password.
Note: You can install PHPMyAdmin for a graphical user interface of MySQL by executing

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

5. restart apache for the last time

sudo /etc/init.d/apache2 restart

Congratulions your LAMP system is installed and running :D
Happy Coding

//Jo

UPDATE:
Due to the large number of people emailing about installing/running phpmyadmin.
Do the following:

sudo apt-get install phpmyadmin

The phpmyadmin configuration file will be installed in: /etc/phpmyadmin
Now you will have to edit the apache config file by typing

sudo vi /etc/apache2/apache2.conf

and include the following line:

Include /etc/phpmyadmin/apache.conf

Restart Apache

sudo /etc/init.d/apache2 restart

Another issue was making mysql run with php5
First install these packages:

sudo apt-get install php5-mysql mysql-client

then edit php.ini and add to it this line : ” extensions=mysql.so” if it isnt already there

sudo vi /etc/php5/apache2/php.ini

Restart Apache

sudo /etc/init.d/apache2 restart

Hope this helps :)

smarty or CI templating

As I am very new to both smarty and template class of CI, so I found both interesting, as smarty is full fledged template engine, it must full fill the transparency between the designer and the programmer, but in terms of the CI template class, its very easy to use as I am very friendly to CI, so found not bit easy to use it. User guide provides full help to use the template class.

I tried to make the job of designer a bit easier so have a look.

As we know we can load model in the Controller, so we can also call the model in the View class too, so starting from the main template we will move to the controller, I know it’s a wrong approach and it disturbs the flow schema, but later we will move as per the flow too.

This is how the template will look like:

{header}

{left_panel}{center_content}{right_panel}

{footer}

now, what is required from the controller

$result[‘left_panel’]=$this->MyModel->func_name();

rather than calling the load view function use:

$this->parser->parse('blog_template', $result); to provide data to the view file, blog_template is the blog_template.php file.

Only drawback according to me in template parsing class of the CI Is that it won’t accept .tpl or any other extention. But smarty will help.

What will model do:

Model will use data loaded from the database and load it into the view file. Seems very confused I will soon add some controller, model and view file in order to explain it more easily.

Saturday, January 26, 2008

Magic of hook in CI

First change config.php in cofig directory

Search for $config['enable_hooks'] = false; make it ‘true’;

Add following in config/hook.php file


$hook['post_controller_constructor'] = array(

'class' => 'getSystem',

'function' => 'check',

'filename' => 'getsystem.php',

'filepath' => 'hooks'


);



For better configuration, try getting help from user_guide.

Create getsystem.php file in application/hooks directory

And paste the following:


<?php

//change the table name

if (!defined('BASEPATH')) exit('No direct script access allowed');

class getSystem

{

function check()

{

$CI =& get_instance();

$CI->db->query(”SELECT * FROM table_name”);

define('MAIL',true);

}

}

?>

try this controller

<?php

class Welcome extends Controller {

function Welcome()

{

parent::Controller();

}

function index()

{

echo MAIL;

$this->load->view('welcome_message');

}

}

?>

Integrating smarty in CI

Create one directory named ‘applications/init’.
create one file named ‘applications/init/init_mysmarty.php’
paste following in it:

if ( ! class_exists('MySmarty'))
{
require_once(APPPATH.'libraries/MySmarty'.EXT);
}

$obj =& get_instance();
$obj->mysmarty = new MySmarty();
$obj->ci_is_loaded[] = 'mysmarty';

?>

create one file named ‘applications/libraries/MySmarty.php’
paste following in the class :

class MySmarty extends Smarty{

function __construct()
{
$this->compile_dir = APPPATH . "views/templates_c";
$this->template_dir = APPPATH . "views/ templates";
log_message('debug', "Smarty Class Initialized");
}
}
?>

paste “applications/libraries/libs” of smarty in libraries of application : refer to MySmarty.php class for the path. Create ‘templates_c’ and ‘templates’ in views directory

Try this controller:

function Blog()
{
parent::Controller();
$this->load->library('mysmarty');
}
function index()
{

$this->mysmarty->assign('title',"Welcome");
$this->mysmarty->assign('content',"Hello!");
$smarty_array =array('one','two','three','four');
$this->mysmarty->assign('forloop',$smarty_array);
$this->mysmarty->display("basic.html");
}
}
?>
basic.html
{$title}{$content}


{section name=i loop=$forloop}
{$forloop[i]}


{/section}

jquery cool sliding menu

first have a look over the cool styling menu which we are going to make from the jquery.

http://www.getintothis.com/pub/projects/rb_menu/

menu.html

   

I also made a new empty javascript file - called menu.js - that will contain the menu code; include this as well.

menu.html

   

Inside my HTML body I created some nest UL’s:

menu.html

   


  • Test 1

    • Sub element 1

    • Sub element 2



I applied some CSS styling to the menu, but I won’t cover it here, since this is a JQuery tutorial - you can find the complete example with styling in the attached zip file.

Now that we have our HTML set up, we can open up menu.js and code the menu behaviours.

menu.js

 1  var obj = null;
2
3 function checkHover() {
4 if (obj) {
5 obj.find('ul').fadeOut('fast');
6 } //if
7 } //checkHover
8
9 $(document).ready(function() {
10 $('#Nav > li').hover(function() {
11 if (obj) {
12 obj.find('ul').fadeOut('fast');
13 obj = null;
14 } //if
15
16 $(this).find('ul').fadeIn('fast');
17 }, function() {
18 obj = $(this);
19 setTimeout(
20 "checkHover()",
21 400);
22 });
23 });

Starting at line 9: $(document).ready(function() { ... }); is similar to your basic window.onload method of attaching handlers, but is a bit more intelligent. This JQuery function checks the document and is run the moment the DOM is ready to be manipulated, this means you don’t have to wait for images to load like window.onload.

In super-summary, the ready function is where the magic starts, and is your entry point to JQuery code.

Line 10 is an example of JQuery’s element selectors. $('#Nav > li') looks for all LI elements that are children of the node with Nav ID. Read about selectors here.

Now that we’ve selected the elements we want, we specify that the hover event will have an anonymous function attached to it as specified. This means that whenever an LI with a parent of ID Nav is hovered over with the mouse, the specified function will execute. The hover event actually takes two parameters, both functions. The first is the method to run when the mouse enters the object, and the second is the method to run with the mouse leaves the object.

Line 11: check if obj exists (if it does, it means that an element is already visible, line 18), if it is set, find the child UL node (find operates in the scope of the object it’s called on, so if obj is an LI in a #Nav node, then find('ul') finds all UL’s inside that LI), and execute a fadeOut on it. fadeOut and fadeIn are built-in JQuery special effects, and take a speed parameter, ‘fast’, ‘normal’ or ’slow’. Once we’ve dealt with the previously shown object, we fadeIn the currently hovered element.

Line 17 shows the second parameter to the hover function - we set obj to the current element, and then use setTimeout to specify that the checkHover function must be executed in 400 milliseconds. The reason I’ve done it this way, is to prevent the menu from instantly disappearing when you mouse-off it - the user has 400 milliseconds before the fadeOut is called on the menu, which gives them time to correct their mouse positioning if they hover off the element for a moment.

Scarily enough, this is all the code needed to get a mostly-functioning pop-up menu! There’s a lot I don’t know about JQuery, so I might’ve messed something up, but at least it works. The example CSS styling only works in Firefox - IE has some issues with it, but since it’s just an example, I can’t be bothered to fix it. Hopefully that’s enough to get you started on with JQuery - unfortunately WordPress isn’t the best platform for code tutorials, and neither am I the best teacher!





my sample code: change the path of


<script src="http://code.jquery.com/jquery-latest.js"></script>

$(document).ready(function() {

//ready function acts as a body on load

$('#navi > li').hover(function(){

$(this).find('ul').fadeIn('fast');

},function(){

$(this).find('ul').fadeOut('fast');

}

)

});

</script>

<style>

#navi

{

cursor:pointer;

}</style>

<ul id="navi">

<li>my

<ul>

<li>a</li>

<li>b </li>

<li>c </li>

<li>d </li>

<li> e</li>

</ul>

</li>

<li>myenu

<ul>

<li> f</li>

<li>g </li>

<li> h</li>

<li> i</li>

<li> j</li>

</ul>

</li>

<li>struc

<ul>

<li> k</li>

<li> l</li>

<li> m</li>

<li> n</li>

<li> o</li>

</ul>

</li>

</ul>

Saturday, January 19, 2008

Initial step for AJAX

Sample code for getting data from a DIV tag and giving the data to a DIV.

Technologies used:
HTML and Javascript

<html>

<head>

<script>

function value_feed()

{

var temp ="hello";

var value1=document.getElementById("value1").innerHTML;

document.getElementById("value1").style.visibility="visible";

document.getElementById("value2").innerHTML='<b>'+'<font color ="red">'+temp+" "+value1+'</b>'+'</font>';

//document.getElementById("value1").style.visibility="hidden";

}

function hi()

{

setTimeout("value_feed()",4000);

}

</script>

</head>

<body onload="hi()">

<div id="value1">hi how r uklashdskljdskld</div>

<div id="value2"> </div>

</body>

</html>