thephpx

codeigniter, php, mysql, xhtml, css, jquery, flex web-development blog

Follow me on TwitterRSS Feeds

  • Home
  • About
  • Site Map
  • Archives

jQuery: input array object validation

Jul 26th

Posted by admin in development

No comments

Use of input array objects in ajax based forms where we want to give users open ended options to add unlimited number of items and then process them on form submission is very common now a days. As the input elements all have the same name and assuming no class or id attribute is available, validation can be a big pain in the back side.

The following code excerpt shows how to validate in such a scenario -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
<meta http-equiv="content-type" content=
"text/html; charset=us-ascii" />
<title>Hello World</title>

<script type="text/javascript" src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
//<![CDATA[
      function checkname(fieldname){
      var field = document.getElementsByName(fieldname+"[]");

      var status = 1;
      for(i=0;i<field.length;i++){
        if(status > 0){
          if(field[i].value == ''){
            status = 0;
          }
        }
      }
      
      if(status == 0){alert('The field can not be empty!');}
    }
//]]>
</script>
</head>
<body>
<form method="post" action="" name="form" id="form">
 <input type="text" name="faisal[]" value="" />
 <input type="text" name="faisal[]" value="" />
 <input type="text" name="faisal[]" value="" />
 <input type="text" name="faisal[]" value="" />
 <select name="ahmed[]">
  <option value="">None</option>
  <option value="1">1</option>
 </select>
 <input type="submit" value="test" onclick="checkname('ahmed');" />
</form>
</body>
</html>

Comments and queries are welcomed :)

thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
input array element, jquery, validation

codeigniter: facebook social plugin – like button helper

Jun 20th

Posted by admin in codeigniter

No comments

Hello everybody,

I have just created a short helper to create facebook like button dynamically for any content, by just giving-in the URL of the page. Hope this one also helps you like my other helpers :)

Helper function:

  1.  
  2. if(!function_exists(‘facebook_like’)){
  3.  function facebook_like($url){
  4.  $formlink=‘<iframe src="http://www.facebook.com/plugins/like.php?href=’;
  5.   $formlink .= urlencode($url);
  6.   $formlink .= ‘;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>’;
  7.                
  8.   return $formlink;
  9.   }
  10.  }
  11.  

Usage:

  1.  
  2. <?php
  3. $url = current_url();
  4. echo facebook_like($url);
  5. ?>
  6.  

Note:
As you can see the function requires you to use the codeigniter’s native URI helper.

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
codeigniter, facebook, facebook helper, facebook like button, facebook social plugins, like button, social plugins

codeigniter: helper function to call library or model function in view

May 16th

Posted by admin in Uncategorized

1 comment

Hi I am back again,

This time with two helper function that lets you call any function from any model or library, given you already have the model or library loaded into the instance.

This one calls a library function with a single parameter being passed.

  1. if(!function_exists(‘call_lib_func’)){
  2.  function call_lib_func($library_name, $function_name, $parameters=null){
  3.   $ci = &amp;get_instance();
  4.   $ci->load->library($library_name);
  5.   return $ci->$library_name->$function_name($parameters);
  6.  }
  7. }

The next one calls a model function with a single parameter being passed.

  1. if(!function_exists(‘call_mod_func’)){
  2.  function call_mod_func($model_name, $function_name, $parameters=null){
  3.   $ci = &amp;get_instance();
  4.   $ci->load->model($model_name);
  5.   return $ci->$model_name->$function_name($parameters);
  6.  }
  7. }

As of now multiple parameter are not yet supported but I will soon post an extension of these two functions that will support multiple parameters. If you choose to use any of these functions feel free to use but a link back to my site is appreciated :)

thanks,

thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
call function view, codeigniter, function in view, view helper

Codeigniter: Helper – Create breadcrumb from url

May 12th

Posted by admin in codeigniter

2 comments

Breadcrumb is a navigational tool that developer often integrate in their application to give easy access to different segment of the application. This is used in applications which has multiple sequence of activities.

The following code will go into your helper file and you have to call create_breadcrumb(); function to get the formatted html text;

  1. if(!function_exists(‘create_breadcrumb’)){
  2. function create_breadcrumb(){
  3.   $ci = &amp;get_instance();
  4.   $i=1;
  5.   $uri = $ci->uri->segment($i);
  6.   $link = ‘<ul>’;
  7.  
  8.   while($uri != ”){
  9.     $prep_link = ”;
  10.   for($j=1; $j<=$i;$j++){
  11.     $prep_link .= $ci->uri->segment($j).’/';
  12.   }
  13.  
  14.   if($ci->uri->segment($i+1) == ”){
  15.     $link.=’<li>» <a href="’.site_url($prep_link).’"><b>’.$ci->uri->segment($i).’</b></a></li> ’;
  16.   }else{
  17.     $link.=’<li>» <a href="’.site_url($prep_link).’">’.$ci->uri->segment($i).’</a></li> ’;
  18.   }
  19.  
  20.   $i++;
  21.   $uri = $ci->uri->segment($i);
  22.   }
  23.     $link .= ‘</ul>’;
  24.     return $link;
  25.   }
  26. }
  27.  

If the current url is http://www.domain.com/user/add then the create_breadcrumb() function will return -

  1. » user » ad

Here user is linked to http://www.domain.com/user/ and add is linked to http://www.domain.com/user/add

This is generated by calling in the view file. Try it out and let me know how it went :)

thanks,

thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
breadcrumb, codeigniter, navigation breadcrumb

Codeigniter: Helper – absolute path helper

May 12th

Posted by admin in codeigniter

No comments

Recently I decided to give some more time to my blog and write some short but interesting posts. I will be writing some posts about custom helper functions that I have written which helps me in application development.

First on the list is a absolute path helper which creates an absolute path, relative to the base of the application. I call this function base_path(‘relative/url’);

  1. if(!function_exists(‘base_path’)){
  2.     function base_path($relative_path_location){
  3.         return base_url().$relative_path_location;
  4.     }
  5. }

The above is the code which will go into your helper file. The function formulates an absolute url from the given relative path based on base path of the application directory. It uses the existing base_url() helper function in codeigniter. So, you have make sure the URL helper is already loaded.

Example:

Suppose you want to tag an image which is located at “application-root/images/picture.jpg” to give its absolute URL in the img tag you can type as follows in your template/view file.

  1. <img src="<?php echo base_path(‘images/picture.jpg’);?>" alt="picture"/>

If you application is hosted at domain.com then it will give http://www.domain.com/images/picture.jpg as the returned path where http://www.domain.com/ is the base_url();

thanks,

thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
absolute path, base_url(), codeigniter, template path

PHP Simple HTML DOM Parser, Codeigniter Integration

Oct 25th

Posted by admin in codeigniter

4 comments

Hi all,

I came across “Simple HTML DOM Parser” recently that allows jQuery like DOM selection. This function is quite handy to do some kungfoo DOM manipulation on the fly!

I needed to use it on codeIgniter so modified the files and integrated it into a single codeIgniter library. The original files can be accessed from here its sourceforge project page. For the codeigniter version of the library click here.

  1. $this->load->library(‘domparser’);
  2. $html = $this->domparser->file_get_html(‘http://www.google.com/’);
  3. $rank = $html->find(‘b.gb1′);
  4.  
  5. print_r($rank); // will show all content of tag with class gb1

For further utility functions of the DOM parser visit this link.

Feel free to comment or contact me directly for any query.

take care,

thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
codeigniter, DOM Parser, PHP simple DOM parser

Staged Code-Igniter Web Application Development

Sep 8th

Posted by admin in development

No comments

Today I am going to share a little customization that I do while i develop codeigniter based web application. Now a days in most web application development firms a three-tire development process is followed. This is done to ensure smooth roll-out of the application from development to live.

The three-tire development methodology involves three stages of development servers. First comes the local server which is setup in your laptop or workstation. Then comes the internal test server, which is a central server that holds all the SVN repository as well as hosts the site and make it accessable to all from within the network. This server is also sometimes called staggin server. Last but not the least comes the live server, in most cases its your clients server where you upload your codes after they have passed the QA checks of both local-server and staging-server.

One related aspect of staged development is that in most cases they involve using SVN server for version control. Using SVN, though you can automatically update your server files from SVN server through “svn update” command but if the config file is not configured to take the different servers into consideration you will have to update the config file every time you do update on a server or set separate config file on each server and add the file to ignor list of the SVN repository.

Our way of doing it is to use a single config file and make it lookup the host address to determine which configuration settings to use.  If you are familiar with codeigniter then you already know you will find your config file at system/application/config/config.php.

Find the following line in the config.php file:

  1.  $config[‘base_url’] = "http://localhost/codeigniter/";

Replace the line with the following lines -

  1. if($_SERVER[‘HTTP_HOST’] == "localhost"){
  2.   $config[‘base_url’] = "http://localhost/codeigniter/";
  3. }else if($_SERVER[‘HTTP_HOST’] == "192.168.1.1"){
  4.   $config[‘base_url’] = "http://192.168.1.1/codeigniter/";
  5. }else{
  6.   $config[‘base_url’] = "http://www.live-server.com/codeigniter/";
  7. }

Now all your URL’s will be adjusted based on the server the site is accessed from. Next we will modify the database.php file which is also located in system/application/config/database.php

Find the following line(s) in the database.php file:

  1.  $db[‘default’][‘hostname’] = "localhost";
  2.   $db[‘default’][‘username’] = "root";
  3.   $db[‘default’][‘password’] = "";
  4.   $db[‘default’][‘database’] = "restobolivia";
  5.   $db[‘default’][‘dbdriver’] = "mysql";
  6.   $db[‘default’][‘dbprefix’] = "";
  7.   $db[‘default’][‘pconnect’] = TRUE;
  8.   $db[‘default’][‘db_debug’] = TRUE;
  9.   $db[‘default’][‘cache_on’] = FALSE;
  10.   $db[‘default’][‘cachedir’] = "";
  11.   $db[‘default’][‘char_set’] = "utf8";
  12.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";

Replace the above line with the following once:

  1. if($_SERVER[‘HTTP_HOST’] == "localhost"){
  2.  
  3.   $db[‘default’][‘hostname’] = "localhost";
  4.   $db[‘default’][‘username’] = "root";
  5.   $db[‘default’][‘password’] = "password";
  6.   $db[‘default’][‘database’] = "database_name";
  7.   $db[‘default’][‘dbdriver’] = "mysql";
  8.   $db[‘default’][‘dbprefix’] = "";
  9.   $db[‘default’][‘pconnect’] = TRUE;
  10.   $db[‘default’][‘db_debug’] = TRUE;
  11.   $db[‘default’][‘cache_on’] = FALSE;
  12.   $db[‘default’][‘cachedir’] = "";
  13.   $db[‘default’][‘char_set’] = "utf8";
  14.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";
  15.  
  16. }else if($_SERVER[‘HTTP_HOST’] == "192.168.1.1"){
  17.  
  18.   $db[‘default’][‘hostname’] = "localhost";
  19.   $db[‘default’][‘username’] = "root";
  20.   $db[‘default’][‘password’] = "password";
  21.   $db[‘default’][‘database’] = "database_name";
  22.   $db[‘default’][‘dbdriver’] = "mysql";
  23.   $db[‘default’][‘dbprefix’] = "";
  24.   $db[‘default’][‘pconnect’] = TRUE;
  25.   $db[‘default’][‘db_debug’] = FALSE;
  26.   $db[‘default’][‘cache_on’] = FALSE;
  27.   $db[‘default’][‘cachedir’] = "";
  28.   $db[‘default’][‘char_set’] = "utf8";
  29.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";
  30.  
  31. }else{
  32.  
  33.   $db[‘default’][‘hostname’] = "localhost";
  34.   $db[‘default’][‘username’] = "root";
  35.   $db[‘default’][‘password’] = "password";
  36.   $db[‘default’][‘database’] = "database_name";
  37.   $db[‘default’][‘dbdriver’] = "mysql";
  38.   $db[‘default’][‘dbprefix’] = "";
  39.   $db[‘default’][‘pconnect’] = TRUE;
  40.   $db[‘default’][‘db_debug’] = FALSE;
  41.   $db[‘default’][‘cache_on’] = FALSE;
  42.   $db[‘default’][‘cachedir’] = "";
  43.   $db[‘default’][‘char_set’] = "utf8";
  44.   $db[‘default’][‘dbcollat’] = "utf8_general_ci";
  45.  
  46. }

The above code will give the server specific database configuration to the application based on the server it is accessed from.

Now save these two files and test your application you should be able to use the same config.php file in different servers if they are properly configured on config.php and database.php

For any further query feel free to leave a comment I will try my best to help you out.

take care,

thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
Code-Igniter, codeigniter, development, Staged, Web Application

Sprintometer as a SCRUM management tool

Aug 6th

Posted by admin in development

No comments

On my endeavor to find the perfect SCRUM project management tool I came across a freeware option named “Sprintometer”. It is not entirely free as it sounds but the options it gives to a manager for free is quite outstanding. The application can be downloaded from their website { sprintometer.com } for free.

Sprintometer support project mangement in both XP and SCRUM methodology. Once you create a project it first of all asks the way the project is going to be managed. Then onward a product backlog can be prepared with stories and tasks assigned to it. Each task then can be assigned to a developer or a coder or a tester.

On the basis of the project specification the application itself generated some very useful charts that give the manager a good understanding about where the project is actually heading. Some of these charts are -

  • Track Chart: Tracks the amount of work done and the amount of work remaining through a line graph.
  • Scope Chart: Shows in hour(s) the amount of work left against a story.
  • Resource and Budget Chart: A matrix showing the resource and cost both story-wise and day-wise
  • Story Readiness Chart: Shows how much closer to completion a story is through a table.
  • Summary Report: Gives a overall report about the story in terms of work done, remaining and days left.
  • Workload Report: This shows the amount of workload taken on by each project team members.

From a project manger perspective it gives me a complete hold on where my project is heading. But the only thing it lacks is integration of team members to give their inputs directly to the system. Hope they are working on it and will be made available to the freeware version in near future :p

take care,

- thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
backlog, product backlog, project management, retrospective, scrum, sprint, sprintometer

Compress PNG files while retaining quality

Aug 2nd

Posted by admin in design

No comments

Most of today’s site uses PNG images due to use of transparencies. While they give a fine solution to the transparency problem with finer edge but it also brings about page load time issues.

To solve this problem i recently came across a PNG file compression utility.  This tiny utility is hosted on Source Forge and can be downloaded from here. This utility claims to have compressed PNG files upto 50%.

Though the utility is somewhat crude and runs in command prompt but there is a nifty post about how to call it from the windows shell.

For the shell add-on you may visit the following post.

take care,

- thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
compress, crush, png

My Zen-Environment for WAMP development

Aug 1st

Posted by admin in development

No comments

Hello everyone,

Every developer has there very own zen settings so do i :) . Today I am going to writing about the stuffs I use while I am at development. If you have any better alternatives or suggestions to these applications please feel free to come forward :)

My preferred application development platform includes the following -

Local Work-Station/Laptop:

  • WAMP – Quick fix windows apache mysql and php server setup
  • Free SMTP – my very own SMTP server
  • TortoiseSVN – my personal undo
  • SQLyog – for MySQL database management
  • FileZilla – for FTP management
  • EclipsePDT – My PHP IDE

Central Repository Server Applications:

  • WAMP – for basic windows, apache, mysql, php server on central repository
  • Free SMTP -  for SMTP server on the central repository
  • KpyM Telnet/SSH Server – for SSH access to my central repository
  • VisualSVN – for SVN repository server management at central repository

That is the whole host of applications that are involved in my development process which I find very helpful and agile. I work on two-stage development, my local workstation/laptop and then to my central repository where I host my SVN repositories and also live demos.

The two stage method has so far proven extreamly helpful, specially if you have a VPS account where you are at your will to install applications.

I hope this one helps you setup your zen environment :p.

take care,

- thephpx

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • Share/Bookmark
apache, mysql, php, portable-smtp, ssh, svn, wamp, windows
12»
  • My latest tweets

    Loading tweets...
    Follow me on Twitter!
  • Categories

    • codeigniter
    • design
    • development
    • efficiency
    • graphics
    • mysql
    • php
    • Uncategorized
    • xhtml
  • Blogroll

    • phpfour
Mystique theme by digitalnature | Powered by WordPress
RSS Feeds XHTML 1.1 Top
Blog WebMastered by All in One Webmaster.