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. :)

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. ;)

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

:)