jump to navigation

Zend_Mail attachment missing line October 14, 2008

Posted by ordinarywebguy in PHP, Zend Framework.
3 comments

If you may ever find hard to make it work using Zend_Mail file attachment and following the documentation here http://framework.zend.com/manual/en/zend.mail.attachments.html, there’s a missing line.

$mail = new Zend_Mail();

$at = $mail->createAttachment($myImage);
$at->type = ‘image/gif’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = ‘test.gif’;

$mail->send();

This should be

$mail = new Zend_Mail();

$myImage = file_get_contents($myImagePath);

$at = $mail->createAttachment($myImage);
$at->type = ‘image/gif’;
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_8BIT;
$at->filename = ‘test.gif’;

$mail->send();

This should work fine now. :)

Google Map Project October 13, 2008

Posted by ordinarywebguy in GMaps, Google Maps, Project Bookmark.
4 comments

Just a project bookmark.

My recent project at YW, Google Map API integration. It also utilizes jQuery, Zend_Db and Zend_Paginator.

Check it out here: http://88.191.66.96/index.php

Don’t use google chrome to open your google notebook October 13, 2008

Posted by ordinarywebguy in Google, Google Chrome, Google Notebook.
2 comments

Exactly as what the title is “Don’t use google chrome to open your google notebook” if you don’t want to lose data in your google notebook. It just happen to me after a click on my notebook section, the data on it was disappeared. And I can’t find a way how to retrieve it. :(

Google Chrome devs what is this going on? I can’t believe it happens. Errr…

Calendar with Zend_Date October 10, 2008

Posted by ordinarywebguy in PHP, PHP Frameworks, Zend Framework.
add a comment

As I’ve started to learn mvc zend framework, I’ve also started to use it as a stack framework library for some of my side projects. This module utilizes the Zend_Date component. See code:

class Calendar {
protected $year;
protected $month;
protected $day;
private $ctr = 0;

public function __construct() {
$date = Zend_Date::now();
$this->year = $date->get(Zend_Date::YEAR);
$this->month = $date->get(Zend_Date::MONTH);
$this->day = $date->get(Zend_Date::DAY);
unset($date);
}

public function viewMonth($year = NULL, $month = NULL, $computation = 0) {
$year = self::_setYear($year);
$month = self::_setMonth($month);

$date = new Zend_Date(
array(
‘year’ => $year,
‘month’ => $month,
‘day’ => 01
)
);

$monthDays = $date->get( Zend_Date::MONTH_DAYS );
$monthName = $date->get( Zend_Date::MONTH_NAME );
$firstWeekDay = $date->get( Zend_Date::WEEKDAY_DIGIT );

$html = ‘<table border=”1″ cellpadding=”4″ cellspacing=”0″>’;
$html .= ‘<tr><td colspan=”7″ align=”center”><b>’ . $monthName . ‘ ‘ . $year . ‘</b></td></tr>
<tr>
<td>Sun</td>
<td>Mon</td>
<td>Tue</td>
<td>Wed</td>
<td>Thu</td>
<td>Fri</td>
<td>Sat</td>
</tr>’;

$html .= ‘<tr>’;

$fWd = $firstWeekDay;
while ($fWd != 0) {
$html .= ‘<td>&nbsp;</td>’;
$fWd–;
}

for ($i = 1; $i <= $monthDays; $i++) {
$this->ctr++;
$is7 = $firstWeekDay + $i;
$html .= ‘<td>’.$i.’</td>’;

// Populate remaining <td>
if ($i == $monthDays) {
$date2 = new Zend_Date(
array(
‘year’ => $year,
‘month’ => $month,
‘day’ => $monthDays
)
);

$tds = $date2->get( Zend_Date::WEEKDAY_DIGIT );

while ($tds != 6) {
$html .= ‘<td>&nbsp;</td>’;
$tds++;
}

unset($date2);
}

if ( ($is7 % 7) == 0) {
$html .= “</tr>\n<tr>”;
}

}

$html .= ‘</tr>’;
$html .= ‘</table>’;

return $html;
}

public function viewYear($year = NULL, $month = NULL, $howManyMonths = NULL) {
$year = self::_setYear($year);
$howManyMonths = ($howManyMonths == NULL) ? 12 : (int) $howManyMonths;

$html = ‘<table border=”0″ cellpadding=”4″ cellspacing=”2″>’;

if ($month != NULL) {
$howManyMonths++;
}

$tmp = 1;
$col = 3;

for ($i = 1; $i <= $howManyMonths; $i++) {

if ($tmp == 1) {
$html .= ‘<tr valign=”top”><td>’;
} else {
$html .= ‘<td>’;
}

if ($month == NULL) {
$html .= self::viewMonth($year, $i, $i);
} else {
$html .= self::viewMonth($year, $month, $i);

if (($month % 12) == 0) {
$year++;
}
$month++;
}

if ($tmp == $col) {
$tmp = 1;
$html .= ‘</td></tr>’;
} else {
$tmp++;
$html .= ‘</td>’;
}
}

$html .= ‘</html>’;

return $html;
}

public function getMonth() {
return $this->month;
}

public function getDay() {
return $this->day;
}

public function getYear() {
return $this->year;
}

private function _setYear($year = NULL) {
return ($year == NULL) ? $this->year : $year;
}

private function _setMonth($month = NULL) {
return ($month == NULL) ? $this->month : $month;
}
}

$cal = new Calendar;
$month = isset($_REQUEST['month']) ? (int) $_REQUEST['month'] : $cal->getMonth();
$day = isset($_REQUEST['day']) ? (int) $_REQUEST['day'] : $cal->getDay();
$year = isset($_REQUEST['year']) ? (int) $_REQUEST['year'] : $cal->getYear();

echo $cal->viewMonth($year, $month);

It has still a lot of improvements. Feel free to modify it. ;)

Java == New Machine || Upgrade May 9, 2008

Posted by ordinarywebguy in Computer, Head First, Java, Self.
add a comment

Yes, I need a new machine or an upgrade after almost a half way reading both Head First Java and Head First Passing SCWCD ebooks. And yes I’m inlove w/ Java. For enforcing me to be code-displined, OOP centric, in short a better developer. Sweet Java!!! But my current PC is kidda slow and old for it. :(

PC Specs:
P4 1.5 GHz
1 Gig Memory –> Recently added 512MB
200 GB HD
256MB VC

Advisable Upgrade:
Intel Core 2 Duo
Any motherboard
2 Gig Memory

I was also thinking about buying a laptop. Which is better? Desktop or Laptop? Whewww! I wish I have enough budget for a new decent machine for my Java ventures.

I love Zend Framework! It really rocks!!! April 22, 2008

Posted by ordinarywebguy in PHP, PHP Frameworks, Zend Framework.
3 comments

Yes, I just can’t stop loving to learn it and being inspired by Dohdoh with his tutorials.
http://www.dohdoh.net/category/zend-framework/

By Zend
http://framework.zend.com/manual/videos

And by others
http://akrabat.com/zend-framework-tutorial/

WHY I LOVE IT?
For some reason, I just get tired of what they say “reinventing the wheel”, building my own PHP framework MK-PHP. Though MK-PHP really makes me better at PHP making everything you want on it (workaround) and so was ZF with lots of ready-made kick-ass vital libraries on it. And I don’t have to rewrite it. Just RTFM and viola!!! :)
PHP Level: +1

:)

Free Icons for your Web Application and more… March 14, 2008

Posted by ordinarywebguy in 3006357, Cool Websites, Downloads, Icons.
add a comment

Last night I was coding for a functionality / module that be able to browse folders and files in a specific specified directory on server or should I say web root directory. I finished testing the code and the only thing left was the layout thinking of making it more appealing that will mimic a windows explorer (I do not the know the term of it in linux, linux explorer?!??) and will be as simple as possible. One factor I should do is to add icons (folder and file). As I consulted Mr. Google about it, nothing decent returned results was given to me. Until a friend of mine pop a message asking how’s everything on me. I told my current scenario and he told me to search “famfamfam”. According to him, it’s the most popular free to download sets of icon. Well, thanks to you my friend. You’re my saviour…

Please check this out for yourself.
http://www.famfamfam.com/lab/icons/silk/

How to beautifully retrieve arrays in PHP? February 29, 2008

Posted by ordinarywebguy in PHP.
2 comments

How?

Cast it to object type. :D

See example:

$info = array(
‘first_name’ => ‘Mitch Khenly’,
‘last_name’ => ‘Pascual’,
‘age’ => 1
);

$info = (object) $info; # the secret :)

You can now access it like this:

$info->first_name;
$info->last_name;
$info->age;

I find and see it more beautiful to retrieve / access arrays that way. It’s more readable. Agree? :)

Head First E-books February 14, 2008

Posted by ordinarywebguy in Books, Design Patterns, E-books, Head First, JSP, Java, OOP.
3 comments

I frustratingly wished and wanted to have a copy of these books … but these e-books make my wish come true.

Head First Java, 2nd Edition
Head First Design Patterns
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam (SCWCD)

and…

more here.

Got to print them out soon… Hehe!

Multiple Constructor in PHP January 31, 2008

Posted by ordinarywebguy in PHP, PHP 5, Programming.
5 comments

How?

See code:

class MultipleConstructor {

private $info = ”;

function __construct() {
$argv = func_get_args();
switch( func_num_args() )
{
default:
case 1:
self::__construct1($argv[0]);
break;
case 2:
self::__construct2( $argv[0], $argv[1] );
break;
}
}

function __construct1($value) {
$this->info = $value;
}

function __construct2($value, $value2) {
$this->info = $value . ” ” . $value2;
}

function get() {
return $this->info;
}
}

$a = new MultipleConstructor(‘Value 1′);
echo $a->get();

$b = new MultipleConstructor(‘Value 1′, ‘Value 2′);
echo $b->get();

Viola!!!