My contemplations and diurnal novelties are publicized here

Archive for July, 2012

Fancy box will slow down your Zend MVC application if used improperly.


We had a Zend application which seems damn slow in IE (all version). We were just cursing IE and thought it all related to IE shit.

Somehow my teammate discovered that when calling a certain action in Zend. There are multiple calls going to hit the server.

Then she discovered a flaw in fancy box that was creating multiple calls to the server to serve PNG file but the path was somewhat similar to calling an action in Zend. This way several times controller initialization occurs.

Suggested Solution:-

Changing src to url in fancybox.css worked

Following is the malicious code inside jquery.fancybox-1.3.4.css

.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_close.png’, sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_nav_left.png’, sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_nav_right.png’, sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_title_over.png’, sizingMethod=’scale’); zoom: 1; }

.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_title_left.png’, sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_title_main.png’, sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_title_right.png’, sizingMethod=’scale’); }

AND

.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_n.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_ne.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_e.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_se.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_s.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_sw.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_w.png’, sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’fancybox/fancy_shadow_nw.png’, sizingMethod=’scale’); }

Solution

.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_close.png), sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_nav_left.png), sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_nav_right.png), sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_title_over.png), sizingMethod=’scale’); zoom: 1; }

.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_title_left.png), sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_title_main.png), sizingMethod=’scale’); }

.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_title_right.png), sizingMethod=’scale’); }

AND

.fancybox-ie .fancybox-bg { background: transparent !important; }

.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_n.png) , sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_ne.png), sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_e.png), sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_se.png), sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_s.png), sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_sw.png), sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_w.png), sizingMethod=’scale’); }

.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(url(../fancybox/fancy_shadow_nw.png), sizingMethod=’scale’); }

Advertisements

How to Become a Better PHP Developer


PHP is probably the most popular web development language right now. At least 20 million domains use PHP and it’s the language used on major sites such as Wikipedia and Facebook as well as in some of the world’s biggest open source projects like WordPress and Drupal.

In this article, I’ll share with you ten things I wish I was told when I was just getting started with PHP development, and I’m hoping you’ll be able to learn a thing or two if you’re just taking your first steps into this awesome web development language.

1. Use PHP Core Functions and Classes

If you’re trying to do something that seems fairly common, chances are, there’s already a PHP function or class that you can take advantage of. Always check out the PHP manual before creating your own functions. There’s no need to create a function to remove the white space at the beginning and at the end of a string when you can just use the trim() function. Why build an XML parser for RSS feeds when you can take advantage of PHP’s XML Parser functions (such as xml_parse_into_struct)?

2. Create a Configuration File

Instead of having your database connection settings scattered everywhere, why not just create one master file that contains its settings, and then include it in your PHP scripts? If you need to change details later on, you can do it in one file instead of several files. This is also very useful when you need to use other constants and functions throughout multiple scripts.


Using a config file is a popular web application pattern that makes your code more modular and easier to maintain.

3. Always Sanitize Data That Will Go into Your Database

SQL injections are more common that you may think, and unless you want a big headache later on, sanitizing your database inputs is the only way to get rid of the problem. The first thing you should do is learn about popular ways your app can be compromised and get a good understanding of what SQL injections are; read about examples of SQL injection attacks and check out this SQL injection cheat sheet.

Luckily, there’s a PHP function that can help make a big heap of the problem go away: mysql_real_escape_string. mysql_real_escape_string will take a regular string (learn about data types through this PHP variables guide) and sanitize it for you. If you use the function together with htmlspecialchars, which converts reserved HTML characters (like <script> becomes &lt;script&gt;), not only will your database be protected, but you’ll also safeguard your app against cross-site scripting (XSS) attacks when rendering user-submitted HTML (such as those posted in comments or forum threads).

4. Leave Error Reporting Turned On in Development Stage

Looking at the PHP White Screen of Death is never helpful except for knowing something is definitely wrong. When building your application, leave error_reporting and display_errors turned on to see run-time errors that will help you quickly identify where errors are coming from.

You can set up these run-time configurations in your server’s php.ini file or, if you don’t have access to override the directives in this file, set them on top of your PHP scripts (using the ini_set() function to set display_errors to 1, but it has its limitations when done this way).

The reason behind turning on error reporting is quite simple — the sooner you know about your errors, the faster you can fix them. You might not care about the warning messages that PHP might give you, but even those usually signal towards a memory-related issue that you can take care of. When you’re done building out your application, turn error_reporting and display_errors off or set their values to a production-ready level.

5. Don’t Over-Comment Your Code

Proper documentation of your code through comments in your scripts is definitely a good practice, but is it really necessary to comment every single line? Probably not. Comment the complicated parts of your source code so that when you revisit it later you’ll quickly remember what’s going, but don’t comment simple things such as your MySQL connection code. Good code is self-explanatory most of the time.

Good Example of Commenting

<?php

 

    /* CONNECT TO THE DATABASE */

 

    $hostname = “localhost”;

    $username = “”;

    $password = “”;

    $dbname = “”;

 

    $connectionStatus = mysql_connect($hostname, $username, $password) or die(mysql_error());

    $selectionStatus = mysql_select_db($dbname) or die(mysql_error());

 

    /* END DATABASE CONNECTION */

 

?>

Bad Example of Commenting

<?php

 

    /* DEFINE THE CONNECTION VARIABLES */

    $hostname = “localhost”; // Hostname

    $username = “”; // Username

    $password = “”; // Password

    $dbname = “”; // Database name

    // Connect to the database or display an error

    $connectionStatus = mysql_connect($hostname, $username, $password) or die(mysql_error());


// Select our database here    

$selectionStatus = mysql_select_db($dbname) or die(mysql_error());

 

?>

6. Keep Favorite Code Snippets Handy

You’ll be coding a lot of the same things throughout your PHP development career, and keeping code snippets always available will help you save a lot of time. There are several apps that can keep and sync your code snippet collection for you, so no matter where you are, you can always have your snippets available. Some apps you can use to corral your code snippets are Snippet, snippely, Code Collector, and Snipplr (web-based).


Most integrated development environments (IDEs) such as Eclipse (which can store code templates) and Dreamweaver (via the Snippets Panel) may have built-in features for storing code snippets.

Even a simple and well-organized directory called snippets that contain text files (or PHP scripts) — and possibly synced in the cloud using an app like Dropbox if you use multiple computers — can do the trick.

7. Use a Good Source Editor to Save You Time

Your editor is where you’ll spend the majority of your time, so you want to use something that helps you save time. Syntax highlighting is a must and definitely something you should be looking for as a software feature. Other bonuses include code hinting, code navigation and built-in debugging tools. All of these features can end up saving you massive amounts of time. An example of a source code editor/IDE for PHP is phpDesigner.


Take the time to get familiar with your source code editor’s features by reading the documentation and reading tutorials online. A bit of time investment in this arena can really streamline your coding workflow.

Check out this list of source code editors for developers as well as this list of free text editors for coders to discover popular code-editing applications.

8. Use a MySQL Administration Tool (Like phpMyAdmin)

I know some crazy hard-core developers who like working with MySQL (the popular Database Management System pairing for PHP) via command line, which, to me, is inefficient and just, well, crazy. It’s a good thing to know how to administer your MySQL database using mysqladmin, but afterwards, you should use a graphical user interface like phpMyAdmin to speed up database development and administration.


phpMyAdmin, in particular, is an excellent open source database viewer/manager that allows you to view your MySQL databases graphically so that you don’t have to waste time doing things via the command line. You can quickly build databases and their tables, export your databases into SQL files, run SQL queries, optimize tables, check for issues, create MySQL database users and set up their privileges quickly, and much more. There is a good chance your web host already has phpMyAdmin installed, and if not, it only takes minutes to install.

Check out this list of the best MySQL database management tools and this list of MySQL apps for alternatives to phpMyAdmin.

9. Use a PHP Framework

It took me a really long time to accept the fact that using a web application development/rapid application development framework would help me out. You have a small learning curve in the beginning, and there will be a lot of reading to do to learn how the API of the framework works, but you get amazing productivity and efficiency benefits later. Using a framework forces you to use better web development patterns that you might not be using right now.

Using a PHP framework pays off big time when you have to share your code with others later on or when you have to work together with someone; it gives you a standardized platform for building web applications. I learned the importance of this the hard way when I had to start hiring other developers.


Some popular PHP frameworks are CakePHP, CodeIgniter, symfony, and Zend.

10. Connect with Other PHP Developers

You don’t know it all. And even if you think you do, there are thousands of others out there that know how to do something better than you do. Join a PHP community like PHPDeveloper and interact with others. By connecting with other developers, you’ll learn better ways of doing the things you’re currently doing.

Copied from http://sixrevisions.com/web-development/10-things-you-can-do-to-become-a-better-php-developer/

Creating S.M.A.R.T. Goals


Copied from http://topachievement.com/smart.html

Specific

Measurable

Attainable

Realistic

Timely

Specific: A specific goal has a much greater chance of being accomplished than a general goal. To set a specific goal you must answer the six “W” questions:

*Who:      Who is involved?

*What:     What do I want to accomplish?

*Where:    Identify a location.

*When:     Establish a time frame.

*Which:    Identify requirements and constraints.

*Why:      Specific reasons, purpose or benefits of accomplishing the goal.

EXAMPLE:  A general goal would be, “Get in shape.” But a specific goal would say, “Join a health club and workout 3 days a week.”


Measurable – Establish concrete criteria for measuring progress toward the attainment of each goal you set.

When you measure your progress, you stay on track, reach your target dates, and experience the exhilaration of achievement that spurs you on to continued effort required to reach your goal.

To determine if your goal is measurable, ask questions such as……

How much? How many?

How will I know when it is accomplished?


 
 

Attainable – When you identify goals that are most important to you, you begin to figure out ways you can make them come true. You develop the attitudes, abilities, skills, and financial capacity to reach them. You begin seeing previously overlooked opportunities to bring yourself closer to the achievement of your goals.

You can attain most any goal you set when you plan your steps wisely and establish a time frame that allows you to carry out those steps. Goals that may have seemed far away and out of reach eventually move closer and become attainable, not because your goals shrink, but because you grow and expand to match them. When you list your goals you build your self-image. You see yourself as worthy of these goals, and develop the traits and personality that allow you to possess them.


Realistic– To be realistic, a goal must represent an objective toward which you are both willing and able to work. A goal can be both high and realistic; you are the only one who can decide just how high your goal should be. But be sure that every goal represents substantial progress.

A high goal is frequently easier to reach than a low one because a low goal exerts low motivational force. Some of the hardest jobs you ever accomplished actually seem easy simply because they were a labor of love.


Timely – A goal should be grounded within a time frame. With no time frame tied to it there’s no sense of urgency. If you want to lose 10 lbs, when do you want to lose it by? “Someday” won’t work. But if you anchor it within a timeframe, “by May 1st”, then you’ve set your unconscious mind into motion to begin working on the goal.
Your goal is probably realistic if you truly believe that it can be accomplished. Additional ways to know if your goal is realistic is to determine if you have accomplished anything similar in the past or ask yourself what conditions would have to exist to accomplish this goal.

T can also stand for Tangible – A goal is tangible when you can experience it with one of the senses, that is, taste, touch, smell, sight or hearing.

When your goal is tangible you have a better chance of making it specific and measurable and thus attainable.

Forceful download using php results in a damaged pdf file


You might be facing this issue in IE “Adobe Acrobat could not open because it is either not a supported file type or because the file has been damaged” off course that’s why you are here.

There exist a plenty of headers that can be included to make your forceful download workable in IE, I have gone through several and mentioned those in reference below.

But the solution that worked from me is extremely simple. (PHP code)

$filename = $this->paramfile;

header(“Content-Type: application/octet-stream”, FALSE);

header(“Content-Disposition: attachment; filename=”.basename($filename));

readfile($filename);

exit;

References:-

  1. http://stackoverflow.com/questions/1218925/php-script-to-download-file-not-working-in-ie
  2. http://stackoverflow.com/questions/49284/file-downloads-in-ie6
  3. http://forums.asp.net/t/1036628.aspx/2/10
  4. http://itworkerdaily.wordpress.com/2007/06/26/php-developper-adobe-pdf-error-message-indicating-adobe-reader-could-not-open-the-file-%E2%80%98xxxfdf%E2%80%99-because-it-is-either-not-a-supported-file-type-or-because-the-file-has-been-corrupt/#more-64
  5. http://itworkerdaily.wordpress.com/category/internet-explorer/
  6. http://www.codingforums.com/archive/index.php/t-70819.html
  7. http://www.codingforums.com/showthread.php?t=70819

How to make legend non-clickable in Ext js pie chart


The solution is simple; all you need to do is to put these lines after the chart is rendered. You can view the live example here

Ext.each(

Ext.getCmp(‘chartCmpConversion’)

.legend.items, function(item) {

item.un(“mousedown”, item.events.mousedown.listeners[0].fn);

})

But, where to place this code can become troublesome. So I pasted the whole code to generate a pie chart below.

<script type=“text/javascript”>
/////////////////////////////////////
Ext.require([‘Ext.data.*’]);
Ext.onReady(function() {
window.generateData = function(n, floor){
var data = [];
data.push({ name: ‘January’ , data1: 1});
data.push({ name: ‘February’ , data1: 2});
return data;
};
window.store1 = Ext.create(‘Ext.data.JsonStore’, {
fields: [‘name’, ‘data1’, ‘data2’, ‘data3’, ‘data4’, ‘data5’, ‘data6’, ‘data7’, ‘data9’, ‘data9’],
data: generateData()
});

});

////////////////////////////////////
Ext.require(‘Ext.chart.*’);
Ext.require(‘Ext.layout.container.Fit’);

Ext.onReady(function () {

var data =generateData(6, 20);
if(data.length>0)
{
store1.loadData(data);
var donut = false,
panel1 = Ext.create(‘widget.panel’, {
height: 200,
width: 245,
renderTo: Ext.get(‘conversionChartInner’),
layout: ‘fit’,
items: {
xtype: ‘chart’,
id: ‘chartCmpConversion’,
animate: true,
store: store1,
shadow: true,
legend: {
position: ‘right’
},
insetPadding: 15,
theme: ‘Base:gradients’,
series: [{
type: ‘pie’,
field: ‘data1’,
showInLegend: true,
donut: donut,
tips: {
trackMouse: true,
width: 140,
height: 28,
renderer: function(storeItem, item) {
var total = 0;
store1.each(function(rec) {
total += rec.get(‘data1’);
});
this.setTitle(storeItem.get(‘name’) + ‘: ‘ + storeItem.get(‘data1’) + ‘%’);
}
},
highlight: {
segment: {
margin: 20
}
}
}]
}
});

Ext.each(
Ext.getCmp(‘chartCmpConversion’)
.legend.items, function(item) {
item.un(“mousedown”, item.events.mousedown.listeners[0].fn);
})

}
});

</script>
<div id=“conversionChart”>
<div id=“conversionChartInner”>
</div>
</div>

References:-

  1. http://stackoverflow.com/questions/6468786/extjs4-pie-chart-problem?s=38106945-6332-41d9-8c9e-1650038acb46
  2. http://www.sencha.com/forum/showthread.php?152086-Disable-Legend-Click-Event-for-ExtJs-Charts&p=852967#post852967

Multiple nested tabs in organictabs jquery


I recently came across a situation where I have to implement multiple tabs within a tab. Googling around doesn’t work for me so I prefer to publish mine. You can see a working example here http://jsfiddle.net/hellowahab/5vtZ6/show/    OR  You can play with the code here http://jsfiddle.net/hellowahab/5vtZ6

Pre-requisites files to include

<script type=”text/javascript” src=”jquery.min.js”></script>

<script type=”text/javascript” src=”organictabs.jquery.js”></script>  (Code can be found from the example above)

Some styling added to the tabs

<style>

/* Generic Utility */

.hide { display: none; }

.clear { clear: both; }

/* Specific to example three */

#main-profile-tab .contents-level-1 { /*background: #eee;*/ padding: 0px 10px 10px 0px; margin: 0 0 5px 0; }

#main-profile-tab ul { list-style: none; }

#main-profile-tab ul li a { display: block; border-bottom: 1px solid #666; padding: 4px; color: #666;

border-radius: 2px;

-moz-border-radius: 2px;

-khtml-border-radius: 2x;

-webkit-border-radius: 2px;}

#main-profile-tab ul li a:hover { background: #999; color: white; }

#main-profile-tab ul li:last-child a { border: none; }

#main-profile-tab .nav { overflow: hidden; margin: 0 0 10px 0; }

#main-profile-tab .nav li { float:left;margin:0 5px 0 0; line-height: 20px; }

#main-profile-tab .nav li.last { margin-right: 0; }

#main-profile-tab .nav li a { display: block; padding: 2px 8px; background: #4eb7cd; color: white; font-size: 11px; text-align: center; border: 0; }

#main-profile-tab li a.current,#main-profile-tab li a.current:hover { background-color: #013775; color: white; }

#main-profile-tab .nav li a:hover, #main-profile-tab .nav li a:focus { background: #999;}

#main-profile-tab .contents-level-1 .headings-level-2 { overflow: hidden; }

#main-profile-tab .contents-level-1 .headings-level-2 li{ float: left; margin:0 5px 0 0; line-height: 20px; /*width: 80px; */ }

#main-profile-tab .contents-level-1 .headings-level-2 li a { display: block; padding: 2px 8px; background: #4eb7cd; color: white; font-size: 11px; text-align: center; border: 0; }

#main-profile-tab .contents-level-1 .headings-level-2 li a:hover { background: #999; color: white; }

#main-profile-tab .contents-level-1 .headings-level-2 li a.current,

#main-profile-tab .contents-level-1 .headings-level-2 li a.current:hover { background-color: #013775; color: white; }

#main-profile-tab .contents-level-1 .contents-level-2 { padding: 5px; }

#main-profile-tab .contents-level-1 .headings-level-3 { overflow: hidden; }

#main-profile-tab .contents-level-1 .headings-level-3 li{ float: left; margin:0 5px 0 0; line-height: 20px; /*width: 80px; */ }

#main-profile-tab .contents-level-1 .headings-level-3 li a { display: block; padding: 2px 8px; background: #4eb7cd; color: white; font-size: 11px; text-align: center; border: 0; }

#main-profile-tab .contents-level-1 .headings-level-3 li a:hover { background: #999; color: white; }

#main-profile-tab .contents-level-1 .headings-level-3 li a.current,

#main-profile-tab .contents-level-1 .headings-level-3 li a.current:hover { background-color: #013775; color: white; }

#main-profile-tab .contents-level-1 .contents-level-3 { padding: 5px; }

#tabbed-area-2 { padding-bottom: 10px; }

</style>

Actual Javascript that will help you create tabs

<script>

$(function () {

// Nested tabs

$(“#main-profile-tab”).organicTabs({

headingsSelector: “.headings-level-1”,

contentsSelector: “.contents-level-1”

});

$(“#main-profile-tab .contents-level-1”).organicTabs({

headingsSelector: “.headings-level-2”,

contentsSelector: “.contents-level-2”

});

$(“#main-profile-tab .contents-level-1 #tabbed-area-3”).organicTabs({

headingsSelector: “.headings-level-3”,

contentsSelector: “.contents-level-3”

});

});

</script>

You HTML Code here

<div id=”page-wrap”>
<div id=”main-profile-tab”>
<ul>
<li><a href=”#featured”>Tab One</a></li>
<li><a href=”#core”>Tab One containing two more tabs</a></li>
</ul>
<div>
<div id=”featured”>
<p>
This is supposed to contain Tab one data.</p>
</div>
<div id=”core”>
<p>
Core Stuff in here!</p>
<div id=”tabbed-area-2″>
<ul>
<li><a href=”#core-1″>Nested Tab 1</a></li>
<li><a href=”#core-2″>Nested Tab 1</a></li>
</ul>
<div>
<div id=”core-1″>
First nested tab’s content
</div>
<div id=”core-2″>
Second nested tab’s content
</div>
</div>
<div>
</div>
</div>
<div id=”tabbed-area-3″>
<ul>
<li><a href=”#corer-1″>Nested Tab 3</a></li>
<li><a href=”#corer-2″>Nested Tab 4</a></li>
</ul>
<div>
<div id=”corer-1″>
Third nested tab’s content
</div>
<div id=”corer-2″>
Forth nested tab’s content
</div>
</div>
<div>
</div>
</div>
</div>
</div>
</div>
</div>

Hope I don’t need to explain the code. I any problem do post the comment.


How to force pdf files to download in PHP MVC framework (Zend)


Add a download button using following code:-

<a
id=”pdfDownloadLink” target=”_blank” href=”#”><img
src=”<?php
echo
$this->baseUrl(); ?>/images/icon/downloadpdf.png”
/></a>

Use following lines of jquery to change the href attribute on fly:-

$(“#pdfDownloadLink”).attr(‘href’, ‘<?php echo $this->serverUrl() . $this->baseUrl(); ?>/index.php/report/downloadpdf/file/?file=’ + encodeURIComponent(downloadURL));

In Zend the URL follow the following conventions

Index.php/controller/action/param/value/param2/value2/param2/value2…

So providing file url will create problem so I used

/file/?file=FileURL

You also need to add downloadpdf action to your controller

public function downloadpdfAction()   {

$params = $this->getRequest()->getParams();

$this->view->paramfile = $params[‘file’];

 }

And in the view you can simple use following plain php code to download the file

<?php

$file= $this->paramfile;

header (“Content-type: octet/stream”);

header (“Content-disposition: attachment; filename=”.$file.“;”);

header(“Content-Length: “.filesize($file));

readfile($file);

exit;

?>


%d bloggers like this: