Monday, February 27, 2012

How to get the path to the public directory in a view of Zend Framwork...

There are many view helpers in Zend Framwork, out of those "baseUrl" helper can be used to get the base path of the application.

Ex:
headLink()->appendStylesheet($this->baseUrl('css/global.css')) ?>


For more details:
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.baseurl

Time goes by so fast...

I haven't written anything in my blog for a long time, actually, this was completely forgotten through out the last one and half years, although there are many things to write about. This year, I am hoping to write some more things, at least the blog will be used as a my own reference to keep the things documented.

Last year, one of my best friends got a really nice idea, that is to document each an every little programing "how to"s for later reference in a blog. Now, that site has grown, and it's a nice place to find those day to day tech bits. - http://techbitsdaily.blogspot.com/

So, I am also going to add a new category called "howto" for keeping my day to day stuff. And this will be useful for keeping little things documented, to reduce the time wast of re-searching.

Saturday, July 31, 2010

BIRT reporting system for PHP web applications

BIRT is an Eclipse-based open source reporting system for web applications, especially those based on Java and J2EE. BIRT has two main components: a report designer based on Eclipse, and a runtime component (Birt Viewer) that you can add to your app server. [ref: http://www.eclipse.org/birt/phoenix/intro/]

Although BIRT is designed to be integrated into a J2EE web application, you can use it in any other development environment such as PHP. A brief description about how it works is given below.

To design the reports, BIRT designer should be installed. There are few ways to do that, and those are described in - http://www.eclipse.org/birt/phoenix/build/#introduction . Designing reports is extremely easy, and tools are there to bind data with database tables/fields, build queries etc..

The next thing is, there should be a instance of BIRT report viewer installed in a web server like tomcat. How to install BIRT viewer in tomcat is described here - http://www.eclipse.org/birt/phoenix/deploy/viewerSetup.php#install_jdbc (BIRT viewer is the tool that you used to view the reports). After installing the viewer, report design files can be hosted there.


Now you can request the report . Given below is a very basic example, which passes only one parameter to the Report Viewer. How PHP applications can use BIRT is described here - http://www.eclipse.org/birt/phoenix/deploy/usingPHP.php#dynamic .

     /*
     * @param sfWebRequest $request
     */
    public function executeTestReport(sfWebRequest $request){

        $repName = "new_report.rptdesign";
        // Redirect browser
        $dest = "http://localhost:8080/birt-viewer/frameset?__report={$repName}";
        header("Location: $dest" );
        die();
    }

http://www.eclipse.org/birt/phoenix/tutorial/ - This Basic Tutorial walks you though the steps to build a basic listing report and introduces the basic BIRT concepts.

Saturday, July 17, 2010

How to split dictionary files in Symfony

Mainly, there are two ways to split the translation files in symfony.

01)

You can split the translation file into several dictionary files, with a certain name. For example, you can split the messages.si.xml file into these two (or more) files in the application i18n/ directory:
  • main.si.xml
  • sub.si.xml
When a translation is not to be found in the default messages.si.xml file, you must declare which dictionary is to be used each time you call the __() helper, using its third argument. For example, to output a string that is translated in the sub.si.xml dictionary, write this:

02)

The other way of organizing translation dictionaries is to split them by module. Instead of writing a single messages.xx.xml file for the whole application, you can write one in each "modules/[module_name]/i18n/" directory.

Ex:

  • symfony/apps/frontend/modules/NewModule/i18n/messages.si.xml
  • symfony/apps/frontend/modules/NewModule/i18n/messages.en.xml
  • symfony/apps/frontend/modules/NewModule/i18n/messages.ta.xml
If you have the same translation element in both main messages file and module specific messages file, the priority will be given to the module specific file's element.

Saturday, February 13, 2010

Common Characteristics of Enterprise Applications

Last week, I was conducting a tech talk about “Architectural Patterns of Enterprise Applications” with our team. The discussion was mainly based on Marin Fowler's famous book “Patterns of Enterprise Application Architecture”. So, I thought, it's good to write something about that in my Blog. Given below are few common characteristics of Enterprise Applications. If any software product has the following characteristics, we can identify it as an Enterprise Application. These ware originally documented by “Martin Fowler”, in his book “Patterns of Enterprise Application Architecture”.

  • Persistent Data - Enterprise applications usually involve persistent data. The data is persistent because it needs to be around between multiple runs of the program—indeed, it usually needs to persist for several years. Also during this time there will be many changes in the programs that use it.
  • Lot of Data - There's usually a lot of data, a moderate system will have over 1 GB of data organized in tens of millions of records—so much that managing it is a major part of the system.
  • Access Data Concurrently - Usually many people access data concurrently. For many systems this may be less than a hundred people, but for Web-based systems that talk over the Internet this goes up by orders of magnitude.
  • Lot of User Interface Screens - With so much data, there's usually a lot of user interface screens to handle it. It's not unusual to have hundreds of distinct screens.
  • Integrate with other Enterprise Applications - Enterprise applications rarely live on an island. Usually they need to integrate with other enterprise applications scattered around the enterprise. The various systems are built at different times with different technologies, and even the collaboration mechanisms will be different.

Wednesday, January 27, 2010

Special characters and text fields

Yesterday I was fixing a bug in one of our customization projects. There was a web form with some input fields. The bug was, when you enter some text in a text field with double quotes (“) data is not saving properly. Actually, the problem was in updating the records. All the characters that is there after the first double quote is truncated. Actually, the fix was very simple. This is something that you may find in any HTML based user interface, and you can fix this within few seconds if you know the exact reason for the bug. The reason for the bug is explained bellow.

In a text field for example, say, we enter a value like – abc”de. Then, you save the form and send this to the data base. Now the value – abc”de – is in a row of a database table, that's okay. After that, if you go to edit the same record, you can see that value in the text field as – abc. The part after the double quote is missing. Usually, in a text box, value is kept in the “value” attribute within double quotes. After we keep some value that contains double quotes, within the value attribute of a input tag, it should looks like given below.




This thing happens only when you get the value from a database table. If you type it manually in the text box, there will be the relevant HTML entities for the double quotes. That should looks like given below.



or


To fix the bug, what we should do is to replace the special characters such as double quotes from the values taken from database. In languages like PHP, this is really simple. You can just use a function such as “htmlentities()”. See the code given below.


Sunday, December 27, 2009

Importance of learning Mathematics for Computing

Today, many IT under graduates don't see the importance of learning mathematics needed for computing. And also there may not any compulsory subjects for mathematics in some degree programs. Basically, learning some areas of Pure Mathematics is very important, if you want to become a real Software Engineer. Actually, when I was schooling, I also didn't know how important it is to learn these maths stuff for the job I am hoping to do in future. So those days, I had no any motivation. But after starting to follow an IT degree, there were some compulsory maths subjects for us, and then I had the motivations to learn them because there was some awareness in me about how these things are used in real life. According to my point of view, this is one of the biggest problems in Sri Lanka's school education system, specially in advanced level, no body knows what the reason for learning these subjects. But some times, there are reasons to be happy about not getting an effort to learn some subject areas in schooling time. For an example, the developers who specialized in Web based Enterprise Applications, Web Application Frameworks etc need not to know anything about Physics, Chemistry, and some areas of Applied Mathematics. But for them, it is extremely important to learn some areas of Pure Mathematics. That is the reason for there are modules for mathematics subjects in many good IT degree programs. Given below is a very simple example to prove this fact. This is the simplest one I could found in my recent works.

In one of our projects, there is an automatic leave allocation system. In that system there are so many things such as monthly allocation of leave, leave accumulations over the years, according to the employees job titles, pay grades, employment statuses, different leave types etc. And, there is a rule, no one can exceed the remaining vacation leave amount more than seventy days. This thing is checked always when assigning leave, copying and bringing forward the leave from previous year. Remaining vacation leave amount is calculated as given below.

remaining_amount = (allocated_amount + brought_forward) - taken_amount


When allocating leave, following simple condition is used to check whether the new leave amount exceeds seventy days.

(new_vacation_amount + brought_forward) - taken_amount >= 70


Now, when allocating vacation leave if the new added amount makes the remaining amount more than seventy, then the new amount should be adjusted so that remaining amount not exceeds seventy. This adjusted value can be calculated simply using the same function given above.

(new_vacation_amount + brought_forward) - taken_amount = 70


new_vacation_amount + brought_forward = 70 + taken_amount


new_vacation_amount = (70 + taken_amount) - brought_forward --->(3)


So, using the third equation, new vacation leave amount can be calculated when the new amount needs to be adjusted to keep remaining amount less than or equal seventy days. Actually, to do a simple things like this, there may be no need of a formal education of mathematics. But in some more complex situations the development time can be reduced by using the knowledge of mathematics. And, also I am not telling here every one needs to have a good maths knowledge to do the things. We all know, there are (were/will be) so many individuals who changed the world by doing good things without having any formal education.