Lately in the PHP/Zend Framework blog world there has been much discussion concerning what constitutes a model in an MVC app. In the current implementation of the MVC apps at work our ZF Form implementations are processed in a corresponding model class as well as a 'notify' method which handles emailing a response after successful submission. I was able to abstract all aspects of the email properties except for the message body.
Most of the time the requirement is to have, basically, the same form view but with the values populate. That usually means creating some long and kludgy looking heredoc or worse a huge string of crazy html intermingled with escapes. Neither solution was very appealing to me. I kept thinking more and more that the email body was really a view. So I treated as such. So my solution was to create a global views directory and a view script that was the email body template and passed it's render method to Zend_Mail instance.
This allows for further separation of models and views. I know that technically the email body should be apart of the model, but far too many times I have to change how the body of the mail looks, not the data, so it lends itself to more of a view.
Please feel free to comment.
::NOTE::
Forms as model architecture taken from http://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your-Models.html
//Example Code
private function _notifyGroup() {
$data = array();
$data = $this->getForm()->getValues();
/**
* Setup view instance to pass to notifier
*/
$view = new Zend_View();
/**
* Assign all form data to view property
*/
$view->assign("formvalues", $data);
/**
* Location of view scripts
*/
$view->addScriptPath(dirname(__FILE__).'/../../../../views');
$body = $view->render('email-templates/mir.phtml');
/**
* Custom notify class that abstracts different 'notify' methodologies. For example you can notfiy
* by writing to a log or email. Email can be Zend_Mail, PEAR or plain ol' php mail()
*/
$notifier = CW_Notify::factory('mail_zend', $body, $options['email']);
$notifier->notify();
}
Saturday, January 10, 2009
Using Zend View for Email Message Body in Your Model
Labels:
email,
models,
zend form,
zend framework,
zend view
Location:
Memphis, TN, USA
Monday, November 17, 2008
New Site Launched - St. Mary's
The St. Mary's Catholic Church website was a volunteer project that I did. Serving the greater Mid South with it's numerous ministries I wanted to give them a professional web presence. The site utilizes the Zend Framework to access Google services as well as custom helper classes that I wrote to simply rendering.
Enjoy.
http://www.stmary-memphis.com/
Enjoy.
http://www.stmary-memphis.com/
Friday, September 5, 2008
Design Overhaul
I finally got a chance to redesign www.randomthoughtprocess.com. The old design had been sitting out there for 5 years. I minimalised the design, made it pure CSS and got rid of content that wasn't be accessed. The main purpose of the site is to showcase more abstract work.
I also converted www.mckinna-wiles.com over from information and media about my wife and I to a site dedicated to our daughter McKinna Wiles.
I also converted www.mckinna-wiles.com over from information and media about my wife and I to a site dedicated to our daughter McKinna Wiles.
Labels:
mckinna,
random thought process,
redesign,
site design
Monday, August 25, 2008
Label Me
Of the API features that Google offers for their Blogger service the one that I was most surprised to see missing is a method to retrieve all the tags(category) for a blog. Though listed in their query parameters is the syntax for search by tag/category, the "cloud" was missing. The below code takes care of this missing feature.
::NOTE::
This class will be rolled into my helper classes soon.
class CW_Blog_Util {
const BLOGGER_URL = 'http://www.blogger.com/feeds/blogId/posts/default';
/**
* associative array holding blog tbl properties
*
* @var array
*/
private $_blogs = array();
/**
* blog title
*
* @var string
*/
private $_title = "";
private $_gDataQuery = null;
private $_gQuery = null;
public function __construct() {
$this->_gQuery = new Zend_Gdata();
}
public function getAllEntries() {
$query = $this->_getGdataQuery();
$feed = $this->_gQuery->getFeed($query);
return $feed;
}
public function getLatestBlog() {
$query = $this->_getGdataQuery();
$feed = $this->_gQuery->getFeed($query);
return $feed->current();
}
public function getBlogListByTag($tag) {
$query = $this->_getGdataQuery();
$query->setCategory($tag);
$feed = $this->_gQuery->getFeed($query);
return $feed;
}
public function getBlogLabels() {
$labels = array();
foreach ($this->getAllEntries() as $attr) {
for ($i = 0; $i < count($attr->category); $i++) {
$labels[] = $attr->category[$i]->term;
}
}
return array_count_values($labels);
}
private function _getGdataQuery() {
$this->_gDataQuery = new Zend_Gdata_Query(self::BLOGGER_URL);
return $this->_gDataQuery;
}
}
// Usage
$blogs = new CW_Blog_Util();
foreach ($blogs->getBlogLabels() as $label => $count) {
print "Label {$label}
";
}
::NOTE::
This class will be rolled into my helper classes soon.
class CW_Blog_Util {
const BLOGGER_URL = 'http://www.blogger.com/feeds/blogId/posts/default';
/**
* associative array holding blog tbl properties
*
* @var array
*/
private $_blogs = array();
/**
* blog title
*
* @var string
*/
private $_title = "";
private $_gDataQuery = null;
private $_gQuery = null;
public function __construct() {
$this->_gQuery = new Zend_Gdata();
}
public function getAllEntries() {
$query = $this->_getGdataQuery();
$feed = $this->_gQuery->getFeed($query);
return $feed;
}
public function getLatestBlog() {
$query = $this->_getGdataQuery();
$feed = $this->_gQuery->getFeed($query);
return $feed->current();
}
public function getBlogListByTag($tag) {
$query = $this->_getGdataQuery();
$query->setCategory($tag);
$feed = $this->_gQuery->getFeed($query);
return $feed;
}
public function getBlogLabels() {
$labels = array();
foreach ($this->getAllEntries() as $attr) {
for ($i = 0; $i < count($attr->category); $i++) {
$labels[] = $attr->category[$i]->term;
}
}
return array_count_values($labels);
}
private function _getGdataQuery() {
$this->_gDataQuery = new Zend_Gdata_Query(self::BLOGGER_URL);
return $this->_gDataQuery;
}
}
// Usage
$blogs = new CW_Blog_Util();
foreach ($blogs->getBlogLabels() as $label => $count) {
print "Label {$label}
";
}
Tuesday, August 19, 2008
McKinna Wiles is Reborn
In anticapation for my daughter, McKinna Wiles, birth I have revamped http://www.mckinna-wiles.com/ using Wordpress as the CMS and a modified theme from wpzone.net.
Enjoy
Enjoy
Monday, August 4, 2008
Access XML Nodes From Namespaces With Zend Framework
One of the requirements for a project that I am working on is that a "weather" module display on on of the main pages. At first glance this should be pretty easy. While working on it I noticed that I wanted to access more of the information that the feed had available. I found plenty of tutorials on how to access the node values using SimpleXML, but I couldn't find what I was looking for utilizing Zend Framework.
After a quick response from the mailing list and references to the PHP online manual I came up with the solution.
Thanks to Pádraic Brady for the assistance.
After a quick response from the mailing list and references to the PHP online manual I came up with the solution.
Thanks to Pádraic Brady for the assistance.
Zend_Feed::registerNamespace('yweather','http://xml.weather.yahoo.com/ns/rss/1.0');
Zend_Feed::registerNamespace('geo','http://www.w3.org/2003/01/geo/wgs84_pos#');
$feed = Zend_Feed::import("http://weather.yahooapis.com/forecastrss?p=38105");
// Conditional Codes: http://developer.yahoo.com/weather/#codes
$condition = $feed->current()->{'yweather:condition'};
$text = $condition->getDOM()->getAttribute('text');
print "Text {$text}
";
$astronomy = $feed->{'yweather:astronomy'};
$text = $astronomy->getDOM()->getAttribute('sunrise');
print "Sunrise Attribute {$text}
";
$lat = $feed->current()->{'geo:lat'};
$text = $lat->getDOM()->nodeValue;
print "Latitude {$text}
";
Labels:
api,
code,
example,
namespaces,
weather,
webservices,
xml,
yahoo,
zend framework
Friday, July 25, 2008
Come Out, Come Out Where Ever You Are
I made an update to the helper classes and comitted them to the changes in subversion and download version. If a photo has been tagged with a location then the GeoWhere node is returned as a property.
Subscribe to:
Posts (Atom)
