I have a view in HWC where I am using Javascript DHTML date picker script to pick the date and insert into test field. By the way HWC is the PHP-MVC (using codeigniter) application I am working on.

I have a view in HWC where I am using Javascript DHTML date picker script to pick the date and insert into test field. By the way HWC is the PHP-MVC (using codeigniter) application I am working on.
Note: Based on its popularity, updated on 6th june 2011 to clean up code for easy copy paste.
OK readers, here is a simple method to achieve clean urls with your PHP application developed in CodeIgniter.
Please note that this method is applicable only to applications developed in CodeIgniter. Much of the content has been taken from CodeIgniter wiki but rewritten in my own way.
This article explains how to take away “index.php” from your CI application URLs. However, it does NOT remove the need for Index.php, which is the CI front controller i.e. even though Index.php will not appear in the URL, it still needs to be present at the top level of your site (above the /system/ directory). To quote the User Guide,
You can easily remove this file by using a .htaccess file with some simple rules.
You need to perform the following steps to get this working:
Create a new file named .htaccess and put it in your web directory
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
Notes for Windows users:
To create this file you must open Command Prompt and type:
copy con .htaccess [Enter] [Press CTRL + Z]
A blank .htaccess file will be created. Now you can edit it using Notepad or your favorite text editor and copy the script above.
Note: Most Windows editors will assume that you are attempting to save an .htaccess file as a file with an extension and no filename. The Crimson Editor can be used to create and save .htaccess files and other files that have no filename.
Note: If your site is placed in subfolder specify the path in the “RewriteBase /subfolder/” line.
Open your
system/application/config/config.php
and find the line that assigns $config['index_page'] a value, usually:
$config['index_page'] = "index.php";
and change it to:
$config['index_page'] = '';
Save the file.
This means that the apache must be configured to load the mod_rewrite module (or it might have it compiled-in). For module inclusion, usually you have to look for a line like this in httpd.conf or a file loaded by it (hint: use some quick file search utility to grep files with lines containing ‘rewrite’ string):
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
If you’re running Apache2 type
a2enmod
in the console and when prompted
rewrite
to enable mod_rewrite.
On a Windows machine this line might look this way:
LoadModule rewrite_module modules/mod_rewrite.so
If it is commented out (# in front), make sure to uncomment it and save the file. Checking if the corresponding module exists may be a good idea as well (but it usually does).
This means that apache is explicitly configured to allow .htaccess files to override those directives that you use in your .htaccess file from step 1. above.
It seems to be sufficient if you add these two lines to your section where you configure the document root for your CI application:
#... Options FollowSymLinks AllowOverride FileInfo #...
There might be other Options listed, just make sure you have FollowSymLinks as well.
Should you get a 500 Internal Server Error, try the following syntax:
Options Indexes Includes FollowSymLinks MultiViews AllowOverride AuthConfig FileInfo Order allow,deny Allow from all
Works? Congratulations!
Doesn’t work? Ehrrr… well, do not give up; equip yourself with patience, double check all steps above and if it still does not work, post on the forum giving all details of your setup.
<IfModule mod_rewrite.c> ... </IfModule>
Do what is inside only if Apache has the mod_rewrite feature (by in place compilation, or loaded module).
RewriteEngine On
Activate the URL rewriting engine, if not already done (in main Apache configuration file.
RewriteBase /
Define the part of the URL that won’t change nor be used for rewriting. In fact, this part will be removed before processing, and prepended after processing. This’s a good way to use subfolder-independent rewrite rules. For example, if your CodeIgniter index.php is placed in a virtual host directory, like /tests/, set RewriteBase to /tests/.
RewriteCond %{REQUEST_FILENAME} !-f
Condition to meet for RewriteRule activation. Here, we test if the requested filename does not exist.
RewriteCond %{REQUEST_FILENAME} !-d
Same as above, but we test for directory existence.
RewriteRule ^(.*)$ index.php/$1 [L]
If RewriteCond conditions are met, this rule will be applied. It inserts index.php before the requested URI. The $1 represents the part of string enclosed by parentheses in left expression. The [L] means that this rule is the last one if rule is applied (thus stopping rewriting).
The Apache mod_rewrite docs say
While URL manipulations in per-server context are really fast and efficient, per-directory rewrites are slow and inefficient. If you have access to your httpd.conf file, you’ll have better performance if you configure the rewrite rules in there.
You can add something like this to your httpd.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
Configuring mod_rewrite and virtual hosting with Apache 2.2
ServerName www.mydomain.com
DocumentRoot /path/to/ci/directory
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Credits: http://codeigniter.com/wiki/mod_rewrite/
Well I was thinking that the old source code I got from the other guy Nouman who was working on this Home Work Center Project that was and is being coded in CodeIgniter was not very much upto date. I fixed the Javascript issues; in fact a lot of them including the JavaScript date picker calendar. It fits well, works on IE 6, IE7, Safari and Firefox; haven’t yet checked with others. But I am sure it will!. Anyhow the problem I was facing was that in different folders in Views for CodeIgniter , if we are using images, we have to use relative URLs in most of the pages, which gets quite troublesome sometimes. As long as it is the CodeIgniter I am working on, I don’t want to use my own includes having setting of the site because this is why we are using CodeIgniter .
Solution:
So cutting short the details, if you want to use the site’s URL and relative paths according to your site’s base url, here is the solution use site_url(). The link contains all the details you will need to use for your views and it also tells which helpers you need to load.
Fahd Murtaza is the guy behind fahdmurtaza.com: your source for getting your web development projects done. Fahd sepcialises in Open Source Web Development and his favorite is WordPress. This site is a platform to his web development portfolio and blog all on a newly designed responsive website—try viewing it on your mobile.
If after viewing Fahd's portfolio, you think he might be just the guy to hire for your web / application development; check out the web development pricing page, then find out how to hire Fahd with a web development project idea and a brief of requirements.
Fahd Murtaza has put together a number of Web Development Articles that will help you see what he does, how he does it. You will also be able to see the level of work, and passion, that Fahad puts into each and every job. Understanding a little about the process can make the idea of investing good money much more palatable. People have always appreciated my Agile techniques. Its time you