Tuesday, September 11, 2012

CodeIgniter URL Repeating Issue

CodeIgniter is one of good PHP framework to develop full featured web applications. Also it has very good, clean user guides and resources as well. With using its large number of built-in functions, it's really easy to develop functionalities in your web application rather than developing from the scratch.

Since it follows the MVC architecture, your application is capable of MVC features like,

  • Code Reusing
  • Separating of Concerns
  • Less Coupling between the layers.
At least now, let's move to the Title :D. Most of the CodeIgniter beginners suffering from this URL repeating issue when submitting forms specially.

Ex: Here I'm trying to create a new news item with using the create function which is in the news model class in my application. The link to load the news form is
                    localhost/CodeIgniter_2.1.2/index.php/news/create in my case.

When submit the form after adding the news item, application trying to go to a URL, localhost/CodeIgniter_2.1.2/index.php/news/create/localhost/CodeIgniter_2.1.2/index.php/news/create 
(repeating the URL)

I could able to fix this problem by modifying the config.php file(located at application\config directory) as follows.
$config[‘base_url’] = ‘http://localhost/file_upload/’;
$config[‘index_page’] = ‘index.php’;

Earlier I had those fields like this,

$config[‘base_url’] = ‘localhost/file_upload/’;
$config[‘index_page’] = ‘’;

You may note that in $config[‘base_url’] field, I have added the 'http://'  at the starting. This may happen because, the URL version without "http://" is considered as a relative path (which is added to the actual URL when setting an anchor :)).

Hope this may useful to some others on the planet :D.
Cheers!!!

Tuesday, August 14, 2012

Simple Date Picker application with Java

Most of the time when developing desktop applications, it may need calendar components(or Date Picker in the term :)). This is a very simple Date Picker example to those who are little bit familiar with java swing.


  • Go into your favourite java editor and create a file TestDatePicker.java
  • Copy following code and paste at there and save it.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class DatePicker {
    int month = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH);
    int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR);;
    JLabel l = new JLabel("", JLabel.CENTER);
    String day = "";
    JDialog d;
    JButton[] button = new JButton[49];

    public DatePicker(JFrame parent) {
            d = new JDialog();
            d.setModal(true);
            String[] header = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" };
            JPanel p1 = new JPanel(new GridLayout(7, 7));
            p1.setPreferredSize(new Dimension(430, 120));

            for (int x = 0; x < button.length; x++) {
                    final int selection = x;
                    button[x] = new JButton();
                    button[x].setFocusPainted(false);
                    button[x].setBackground(Color.white);
                    if (x > 6)
                            button[x].addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent ae) {
                                            day = button[selection].getActionCommand();
                                            d.dispose();
                                    }
                            });
                    if (x < 7) {
                            button[x].setText(header[x]);
                            button[x].setForeground(Color.red);
                    }
                    p1.add(button[x]);
            }
            JPanel p2 = new JPanel(new GridLayout(1, 3));
            JButton previous = new JButton("<< Previous");
            previous.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                            month--;
                            displayDate();
                    }
            });
            p2.add(previous);
            p2.add(l);
            JButton next = new JButton("Next >>");
            next.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                            month++;
                            displayDate();
                    }
            });
            p2.add(next);
            d.add(p1, BorderLayout.CENTER);
            d.add(p2, BorderLayout.SOUTH);
            d.pack();
            d.setLocationRelativeTo(parent);
            displayDate();
            d.setVisible(true);
    }

    public void displayDate() {
            for (int x = 7; x < button.length; x++)
                    button[x].setText("");
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                            "MMMM yyyy");
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.set(year, month, 1);
            int dayOfWeek = cal.get(java.util.Calendar.DAY_OF_WEEK);
            int daysInMonth = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
            for (int x = 6 + dayOfWeek, day = 1; day <= daysInMonth; x++, day++)
                    button[x].setText("" + day);
            l.setText(sdf.format(cal.getTime()));
            d.setTitle("Date Picker");
    }

    public String setPickedDate() {
            if (day.equals(""))
                    return day;
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                            "dd-MM-yyyy");
            java.util.Calendar cal = java.util.Calendar.getInstance();
            cal.set(year, month, Integer.parseInt(day));
            return sdf.format(cal.getTime());
    }
}

public class TestDatePicker {
 
 public static void main(String[] args) {  
   /////////////Picker/////////////////////////
  JLabel selectDate = new JLabel("Select Date Here ->");
  JLabel selectedDate= new JLabel("Selected Date ->");
        final JTextField text = new JTextField(20);       
        JButton b = new JButton("Select"); //button for calendar popup
        JButton close = new JButton("Close"); //button for close the application
        JPanel pPic = new JPanel();
        pPic.setLayout(new GridLayout(3,2));
        pPic.add(selectDate);       
        pPic.add(b);
        pPic.add(selectedDate);
        pPic.add(text);
        pPic.add(close);
        final JFrame f = new JFrame("Simple Date Picker");
        f.getContentPane().add(pPic);
        f.pack();
        f.setVisible(true);
        b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                 text.setText(new DatePicker(f).setPickedDate());
                }
        });
        ////////////////////////Picker////////////////////////////
      
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
             f.dispose();
            }
        });                
 }  
}
When you run the program, firstly you will see the main frame of the application which looks like,

Then when you hit on 'Select' button, the calendar will be popup as follows

Select what ever the date you like(you can even navigate for other months as well with 'Previous' and 'Next' buttons). The selected date will be included in the text field below the 'Select' button, as follows.

It's done :)
Cheers!!!

Friday, July 27, 2012

සරවණ සිරි සුරණි

සුමුදු සුසිනිඳු සිනිඳු සුදු මුදු සෞම්‍ය සඳවත සුකොමලී
රන් රුවැති රූ රුවැති රතඳර රම්‍ය රසඳුන් රම්බරී
වෙහෙස වෙහෙසන විජිනිපත වන් වසන්තයේ වට වනමලී
නිමක් නැති නිල නුබයි නුඹ නොසැපතෙත් නොවෙනස් නන්දනී

Tuesday, June 19, 2012

ප්‍රිය විප්පයෝගයක් දුටිමි

ටිකක් පරණ තාලයේ යතුරු පැදියක යන කොලුවන් දෙදෙනෙකි. නුවර පිහිටි එකෙකුගේ ගෙදර සිට පේරාදෙණිය කැම්පස් එක පැත්තට යතුරු පැදිය ඇදෙයි. හෙට දිනට මොවුන් කැම්පස් ඇවිත් අවුරුදු හතරකි. පුදුමයකි, මේ කදිම යතුරු පැදිය ගෙදර සිට ගෙන ආ දිනයේත් එහි ආවේ මොවුන් දෙදෙනාමය. අවුරුදු හතර පිරෙන කට කොනේ අවසන් වරට එහි යන්නෙත් ඔවුන් දෙදෙනාමය. ටෙලි නාට්‍යයක පිටපතක් වැන්න.
මින් එකෙකු අද දින සදහටම කැම්පස් හැර දා යන දවසයි. හේ අනෙකාද සමඟ එක්ව හනි හනික කාමරය අස්පස් කර අදාළ පුද්ගලයට යතුරද භාර දී තම සගයා සමග යන්නට පිටත් විය. 
යතුරු  පැදිය පණ ගැන්විණි.
අහෝ කරුමයක මහත! සුවිසල් ගොඩනැගිලි, අරුමෝසම් කඩ පේළි, කන් බෙරය දෙදරවන රිය හඬවල් මැද්දෙන් මේ ගමන යන්නට තිබුණානම් කොතරම් අගනේද? කරුමක්කාර උන්හට මේ හැරයාම කළ යුතුව තිබුණේ හදවතින්ම ආදරය කළ, යහළු යෙහෙළින් සමඟ කෙලිකවටකම් කළ, ජීවිතය ජිවත් වීමට කියාදුන් පුණ්‍ය භූමියක් පසු කරමින්ය. වල, පොලොන්නරුව, ඒ.ටී. , කිරිහළ, ...
දින ගණනකින් වැසි නොලද්දෙන් වියලී ගුරුපැහැ ගැන්ව තිබූ බිමේ, හැමදාමත් වගේ වෙනසක් නැතුව පේන්න තිබුණු වලේ, ..... බෙන්ඩ් එකේ, හැමදාමත් සුව වින්ද තුරු ලතා මඬුල්ලේ, මේ හැරයන්නාට එදානම් පෙනුනේ අර හැමදාමත් දැකපු සුන්දරත්වයනම් නොවේ. කැම්පස් එක බලන්නය කියා පිටෙකෙක් විත් විඳින සුන්දරත්වය, අනේ අපිටත් තිබුණානම් කියා සිතෙන්නේ යම් සේද, එවැනිම වූ හැඟීමකි.
ගිය කාරණය සඵල නොවුවද, එන්නට පළමුවෙන් සෙනෙට් පරිශ්‍රය වෙත යාමටද වරම් ලදහ. ඒද, අන් කවරක් නිසාවත් නොව, සරසවි සිව් වස තුළ හද රැඳී සමාගමයක ඉදිරි වැඩක මුල් පියවර තබනු වස් උපකුලපති තුමා බැහැදැකීමට ය. 
වෙනදාට බොහොම කලබලයෙන් මිනිසුන් එහා මෙහා දුවන, පහළ සිසු සිසුවියන්ගේ හඬින් දෙසවන පිරෙන මහත් වූ සෙනෙට් පරිශ්‍රයද මිනිසුන් නොමැති ඈත පිටිසරක තැනූ, භාවිතයෙන් තොරව මකුළු දැල් බැඳ පාලුවට ගිය උස් පල්ලියක් මෙන් අමුතු වූ මුසල හැඟීමක් දැනවුයේය. වැඩය අසාර්ථක හෙයින් දෙදෙනා ආපසු හැරුනෝය.
අපූරු රථය නැවතත් පණගැන්වීනි. එන්නට මත්තෙන් ඔවුන්ගේ කණ්ඩායමේම තවත් එක සගයෙක් මුණගැසී උහු සමඟද සිව් වසක මතකය අඩු වැඩි වශයෙන් හැඟීම්බර ලෙස මෙනෙහි කොට සමු දී යන්නට පිටත් වුහ. ගමනාන්තය ගලහ හන්දියයි. මිනිත්තු පහක දහයක පමණ වූ ඒ යන කෙටි දුරෙහිදී වුව ලට්ට ලොට්ට පිරවූ පතන්ගර මලු දෙකකුත්, කපු කුඩයකට සමානයයි කිවහැකි ලොකු කුඩයකුත් අතැතිව යතුරු පැදියේ පිටුපස යනෙකාගේ හිතට ගලා ආ සිතුවිලි සමුදායනම් පැය පහකින් දහයකින්වත් කියා නිමකරනු නොහේ. 
කෙසේ වුව අවසානයේ දෙදෙනා ගලහ හන්දියේය. පිටිපස සිටි එකා බිමට බැස්සේය. දෙදෙනාම එකිනෙකාට මොනවදෝ කියන්නට තතනන හැඩකි. පැදගන ආ එකා නුවර යා යුතුය. අනෙකා බස් නැවතුම වෙත යා යුතුය. නමුත් දෙදෙනාගෙන් එකෙක්වත් යන්නෙත් නැත. කිසිත් කරන්නෙත් නැත. ඇස් පනාපිට බොරුව පාමින් හිනැහෙන්නට දඟලති. දෙදෙනාගේම ඇස්වල කඳුළුය. 
කරන්නට දෙයක් නැත. ආවොත් යා යුතුය. ගියොත් ආපසු ආ හැකිය. නොගොස් එන්නට බැරිය. මෙහි ඇත්තේ යාම් සහ ඊම් පමණි. කව්දෝ එසේ කියා ඇත. 
තවත් අනෙකාගේ මුණ දෙස බලන් සිටීමට වෙර නැති කල පිටුපස පැමිණි එකා තම සගයාගේ පිටට තට්ටුවක් දමා, "ගිහින් එන්නම්" යි කියා බස් නැවතුම වෙත පිය මැන්නේය. යන්නට හැර, හොරෙන් අනෙකා දෙස බැලීය. අනෙකාද එසේම වන්නට ඇත. 
ඉමිහිරි සරසවි දිවියක මතකයන් අතරේ පිහිනමින්, නැවතත් මේවා නෑ නොවේදෝයි ලතවෙමින් බසයක් එනතුරු සිටින අතර තම ජංගම දුරකථනය නාදය වුයෙන් එය ගෙන බැලීය. අනෙකාගෙන් කෙටි පණිවිඩයකි. නෙතඟ රැඳී කඳුළු තවදුරටත් ඔහුට අවනත නැතුවා සේය. කුමන විහිලුවක්ද? සිහි විකල් වුවෙකු මෙන් ඔහු කඳුළු නැවතත් උල්පත් වෙත යවන්නට මෙන් උඩ බලයි. වට බලයි. සිටින උන්ට කඳුළු වලට හේතු කියන්නට මෙන් බොරු ඈනුම් යවයි. සමහරක් විටෙකදී හිත සැනසුමට කියන කතාද දුක වැඩි වීමට හේතුවකි. මදි පාඩුවට එවෙලෙහිම තවත් එක් සහෝදරියක් වෙන්වයාම නිමිත්තෙන් මොහු අස්වසන්නට සිත සැනසුම් පණිවිඩ එව්වාය. කියන්නේ ඇත්තය. එහෙත් ඇවිලෙන ගින්නට වැටුනේ පිදුරුය. මෙතැන සිට ඉදිරිය ගැන සිතා හිත හදාගත්තේය.
පුරයේ බසය පැමිණියෙන් එයට ගොඩ වී ගමන් ඇරඹුවේය. මලු උස්සගෙන සරසවියේ සිට නිවෙස බලා යන ඒ ඔහුගේ අවසන් ගමනයි. කාක්කන් රැගෙන නැවතත් එන එකක් නැත.

ප්‍රිය  විප්පයෝගය මෙය යයි සිතමි.


2012/06/18 වන දින 
පේරාදෙණිය සරසවියේ දුටු සත්‍ය සිදුවීමක් ඇසුරෙණි.

Wednesday, June 13, 2012

දෙවන අම්මා ලදිමි සරසවියෙන්...

බැඳීම්  කියන දේවල් මහා පුදුමාකාරයි. කියන්නන් වාලෙ කිව්වට "දාල යද්දී තමයි අගේ තේරෙන්නෙ" කියල, ඒක අත්විඳිනකොට තමයි තේරෙන්නෙ ඇත්ත අර්ථය. සිව් වසරක සරසවි දිවිය තුළ හුඟාක්ම සමීප වුණ, අපේ කණ්ඩායමේ සහෝදරයෙක්ගේ අම්ම, සරසවියෙන් එන දවසේ මට දුන්න මතක සටහන මේ .