<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>alexyz &#187; Zend</title>
	<atom:link href="http://alexyz.com/category/php/zend/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexyz.com</link>
	<description>developer notes</description>
	<lastBuildDate>Tue, 13 Dec 2011 19:09:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Post via jQuery across domains (in this case to a Zend Controller and subsequent view) and display the results</title>
		<link>http://alexyz.com/post-via-jquery-across-domains-in-this-case-to-a-zend-controller-and-subsequent-view-and-display-the-results/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=post-via-jquery-across-domains-in-this-case-to-a-zend-controller-and-subsequent-view-and-display-the-results</link>
		<comments>http://alexyz.com/post-via-jquery-across-domains-in-this-case-to-a-zend-controller-and-subsequent-view-and-display-the-results/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 23:09:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=1392</guid>
		<description><![CDATA[the jQuery posting page, in brief: &#60;document&#8230;&#62; &#60;head&#62; &#60;script src=&#8221;http://code.jquery.com/jquery-1.5.js&#8221;&#62;&#60;/script&#62; &#60;/head&#62; &#60;body&#62; &#60;form id=&#8221;enewsform&#8221; name=&#8221;enewsform&#8221; action=&#8221;http://componentserver/controllername/post&#8221; method=&#8221;post&#8221;&#62; &#60;input type=&#8221;text&#8221; name=&#8221;email&#8221; id=&#8221;email&#8221; value=&#8221;&#60;?php echo $_REQUEST['email']; ?&#62;&#8221; /&#62; &#60;a id=&#8221;submitsubscribe&#8221; title=&#8221;Subscribe&#8221; href=&#8221;javascript:{}&#8221; onclick=&#8221;return false;&#8221;&#62;sign up&#60;/a&#62; &#60;/form&#62; &#60;script src=&#8221;http://components.someserver.com/js/jquery.validation.js&#8221; type=&#8221;text/javascript&#8221;&#62;&#60;/script&#62; &#60;script&#62; $(&#8216;#submitsubscribe&#8217;).click(function(){ $(&#8220;#enewsform&#8221;).submit(); }); $(&#8220;#enewsform&#8221;).submit(function(event) { event.preventDefault(); $( &#8220;#result&#8221; ).html (&#8220;submitting&#8230;&#8221;); var $form = $( this ), term [...]]]></description>
			<content:encoded><![CDATA[<p>the jQuery posting page, in brief:</p>
<p>&lt;document&#8230;&gt;<br />
&lt;<span style="color: #008000;">head</span>&gt;<br />
<span style="color: #0000ff;">&lt;script src=&#8221;http://code.jquery.com/jquery-1.5.js&#8221;&gt;&lt;/script&gt;</span><br />
&lt;<span style="color: #008000;">/head</span>&gt;<br />
&lt;<span style="color: #008000;">body</span>&gt;<br />
&lt;<span style="color: #008000;">form</span> id=&#8221;enewsform&#8221; name=&#8221;enewsform&#8221; action=&#8221;http://componentserver/controllername/post&#8221; method=&#8221;post&#8221;&gt;<br />
&lt;input type=&#8221;text&#8221; name=&#8221;email&#8221; id=&#8221;email&#8221; value=&#8221;&lt;?php echo $_REQUEST['email']; ?&gt;&#8221; /&gt;<br />
&lt;a id=&#8221;submitsubscribe&#8221; title=&#8221;Subscribe&#8221; href=&#8221;javascript:{}&#8221; onclick=&#8221;return false;&#8221;&gt;sign up&lt;/a&gt;<br />
&lt;/form&gt;<br />
<span style="color: #0000ff;">&lt;script src=&#8221;http://components.someserver.com/js/jquery.validation.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</span><br />
<span style="color: #0000ff;">&lt;script&gt;</span><br />
$(&#8216;#submitsubscribe&#8217;).click(function(){<br />
$(&#8220;#enewsform&#8221;).submit();<br />
});</p>
<p>$(&#8220;#enewsform&#8221;).submit(function(event) {<br />
event.preventDefault();<br />
$( &#8220;#result&#8221; ).html (&#8220;submitting&#8230;&#8221;);<br />
var $form = $( this ),<br />
term = $form.find( &#8216;input[name="email"]&#8216; ).val(),<br />
url = $form.attr( &#8216;action&#8217; );</p>
<p>if($.validation.email(term)){<br />
$.getJSON(url + &#8220;?email=&#8221; + term + &#8220;&amp;jsoncallback=?&#8221;, function(data){<br />
$( &#8220;#result&#8221; ).html( data['error'] );<br />
if(data['error']== &#8220;errormatchingstring&#8221;){<br />
$( &#8220;#result&#8221; ).html( &#8220;Seems like it worked&#8221; );<br />
}else{ $( &#8220;#result&#8221; ).html(data['error']); }<br />
});<br />
}<br />
else{ $( &#8220;#result&#8221; ).html (&#8220;Please enter your email address&#8221;); }</p>
<p>});<br />
<span style="color: #0000ff;">&lt;/script&gt;</span></p>
<p>&lt;<span style="color: #008000;">div</span> id=&#8221;result&#8221;&gt;&lt;/<span style="color: #008000;">div</span>&gt;</p>
<p><span style="color: #ff0000;">// the component Zend controller in question receives the post, does whatever it does, renders its view, and we access the results from the view (don&#8217;t forget to pass data to the view with something like this:</span><br />
<span style="color: #0000ff;">$this-&gt; view-&gt; viewresult = $this-&gt; viewData;</span>)</p>
<p><span style="color: #ff0000;">&lt;? php </span><br />
<span style="color: #008000;">echo</span> $_REQUEST['jsoncallback'] . &#8216;(&#8216; . json_encode($this-&gt; viewresult) . &#8216;)&#8217;;<br />
<span style="color: #ff0000;">? &gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/post-via-jquery-across-domains-in-this-case-to-a-zend-controller-and-subsequent-view-and-display-the-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bronto API PHP Class to Send a Contact a particular Message (Zend Helper)</title>
		<link>http://alexyz.com/bronto-class-to-send-a-contact-a-particular-message-zend-helper/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bronto-class-to-send-a-contact-a-particular-message-zend-helper</link>
		<comments>http://alexyz.com/bronto-class-to-send-a-contact-a-particular-message-zend-helper/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 22:36:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bronto]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=1388</guid>
		<description><![CDATA[&#60; ? php class Zend_Controller_Action_Helper_BrontoSendMessage extends Zend_Controller_Action_Helper_Abstract { public $message; public $client; public $viewData; public $list; public $now = &#8220;date(&#8216;c&#8217;)&#8221;; public $recipientObject; public $email; public $contact; public $contactId; private $fromName = &#8216;WHATEVERYOUWOULDLIKE&#8217;; private $fromEmail = &#8216;YOU@YOURMAIL.COM&#8217;; public function login(){ ini_set(&#8220;soap.wsdl_cache_enabled&#8221;, &#8220;0&#8243;); date_default_timezone_set(&#8216;America/New_York&#8217;); $wsdl = &#8220;https://api.bronto.com/v4?wsdl&#8221;; $url = &#8220;https://api.bronto.com/v4&#8243;; $this-&#62; client = new SoapClient($wsdl, array(&#8216;trace&#8217; =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #0000ff;"><span style="color: #ff0000;">&lt; ? php</span><br />
class</span> <span style="color: #008000;">Zend_Controller_Action_Helper</span>_BrontoSendMessage extends <span style="color: #008000;">Zend_Controller_Action_Helper_Abstract</span> {</p>
<p>public $message;<br />
public $client;<br />
public $viewData;<br />
public $list;<br />
public $now = &#8220;date(&#8216;c&#8217;)&#8221;;<br />
public $recipientObject;<br />
public $email;<br />
public $contact;<br />
public $contactId;</p>
<p>private $fromName = &#8216;WHATEVERYOUWOULDLIKE&#8217;;<br />
private $fromEmail = &#8216;YOU@YOURMAIL.COM&#8217;;</p>
<p><span style="color: #800000;">public function login()</span>{<br />
ini_set(&#8220;soap.wsdl_cache_enabled&#8221;, &#8220;0&#8243;);<br />
date_default_timezone_set(&#8216;America/New_York&#8217;);</p>
<p>$wsdl = &#8220;https://api.bronto.com/v4?wsdl&#8221;;<br />
$url = &#8220;https://api.bronto.com/v4&#8243;;</p>
<p>$this-&gt; client = <span style="color: #0000ff;">new</span> SoapClient($wsdl, array(&#8216;trace&#8217; =&gt; 1, &#8216;encoding&#8217; =&gt; &#8216;UTF-8&#8242;));<br />
$this-&gt; client-&gt;__setLocation($url);</p>
<p><span style="color: #ff0000;">// Login</span><br />
$token = &#8220;YOUR BRONTO TOKEN HERE&#8221;;<br />
$sessionId = $this-&gt; client-&gt;login(array(&#8220;apiToken&#8221; =&gt; $token))-&gt;return;<br />
if (!$sessionId) {<br />
<span style="color: #008000;">return</span> &#8220;Login failed&#8221;;<br />
}<br />
$this-&gt; client-&gt;__setSoapHeaders(array(<span style="color: #0000ff;">new</span> SoapHeader(&#8220;http://api.bronto.com/v4&#8243;,<br />
&#8216;sessionHeader&#8217;,<br />
array(&#8216;sessionId&#8217; =&gt; $sessionId))));</p>
<p>$this-&gt; viewData['login'] = &#8220;logged in&#8221;;<br />
}</p>
<p><span style="color: #800000;">public function setContact</span>($email){<br />
$this-&gt; email = $email;</p>
<p>$filter = array(&#8216;email&#8217; =&gt; array(array(&#8216;operator&#8217; =&gt; &#8216;EqualTo&#8217;,'value&#8217; =&gt; $this-&gt; email)));</p>
<p>$this-&gt; contact = $this-&gt; client-&gt;<span style="color: #008000;">readContacts</span>(array(&#8216;pageNumber&#8217; =&gt; 1,<br />
&#8216;includeLists&#8217; =&gt; true,<br />
&#8216;filter&#8217; =&gt; $filter,<br />
));<br />
if(!isset($this-&gt;contact-&gt;return-&gt;id))<br />
{<br />
<span style="color: #ff0000;">//return &#8216;Email not subscribed&#8217;;</span><br />
}<br />
else<br />
{<br />
$this-&gt; contactId = $this-&gt;contact-&gt;return-&gt;id;<br />
//return $this-&gt;contactId;<br />
}</p>
<p>$this-&gt; recipientObject = array(&#8216;type&#8217; =&gt; &#8216;contact&#8217;, &#8216;id&#8217; =&gt; $this-&gt;contactId);<br />
}</p>
<p><span style="color: #800000;">public function setDelivery</span>($messageid){<br />
$delivery = array(&#8216;start&#8217; =&gt; date(&#8216;c&#8217;),<br />
&#8216;messageId&#8217; =&gt; $messageid,<br />
&#8216;fromName&#8217; =&gt; $this-&gt; fromName,<br />
&#8216;fromEmail&#8217; =&gt; $this-&gt; fromEmail,<br />
&#8216;recipients&#8217; =&gt; array($this-&gt; recipientObject),<br />
);</p>
<p>$this-&gt;client-&gt;addDeliveries(array($delivery));<br />
}<br />
}<br />
<span style="color: #ff0000;">? &gt;</span></p>
<p><span style="color: #000000;">called from another Zend Controller as a helper in this fashion:</span></p>
<p>$this-&gt; _helper-&gt;<span style="color: #008000;"> BrontoSendMessage</span>-&gt;<span style="color: #0000ff;">login</span>();<br />
$this-&gt; _helper-&gt; <span style="color: #008000;">BrontoSendMessage</span>-&gt;<span style="color: #0000ff;">setContact</span>($this-&gt; email);<br />
$this-&gt; _helper-&gt; <span style="color: #008000;">BrontoSendMessage</span>-&gt;<span style="color: #0000ff;">setDelivery</span>($this-&gt; messageid);</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/bronto-class-to-send-a-contact-a-particular-message-zend-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Notes: Grabbing a resource from the registry via a view helper</title>
		<link>http://alexyz.com/zend-notes-grabbing-a-resource-from-the-registry-via-a-view-helper/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=zend-notes-grabbing-a-resource-from-the-registry-via-a-view-helper</link>
		<comments>http://alexyz.com/zend-notes-grabbing-a-resource-from-the-registry-via-a-view-helper/#comments</comments>
		<pubDate>Wed, 29 Sep 2010 22:11:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=557</guid>
		<description><![CDATA[Helper (application/views/helpers): class Zend_View_Helper_ImageUrlHelper extends Zend_View_Helper_Abstract { /** * Helper to grab the path to the images directory * @param String $imageName * @param String $imageSize, var for possibly different size requests */ public function ImageUrlHelper($imageName, $imageSize) { $config = Zend_Registry::get(&#8216;config&#8217;); $path = $config-&#62; urlpaths-&#62; productImages; return $path . &#8216;/products_&#8217; . $imageSize . &#8216;/&#8217; . [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Helper (application/views/helpers):</strong></p>
<p><span style="color: #000000;">class <span style="color: #ff0000;">Zend_View_Helper_ImageUrlHelper</span> <span style="color: #008000;">extends</span> <span style="color: #0000ff;">Zend_View_Helper_Abstract</span> {<br />
<span style="color: #ff00ff;">/**<br />
* Helper to grab the path to the images directory<br />
* @param String $imageName<br />
* @param String $imageSize, var for possibly different size requests<br />
*/</span></span> <span style="color: #000000;"><br />
public function ImageUrlHelper($imageName, $imageSize) {<br />
$config = <span style="color: #0000ff;">Zend_Registry::get(&#8216;config&#8217;);</span><br />
$path = <span style="color: #0000ff;">$config-&gt; urlpaths-&gt; productImages;</span><br />
<span style="color: #008000;">return</span> $path . &#8216;/products_&#8217; . $imageSize . &#8216;/&#8217; . $imageName;<br />
}<br />
}</span></p>
<p><strong>application.ini (application/configs):</strong></p>
<p><span style="color: #0000ff;">urlpaths.productImages</span> = &#8220;/path/images/product_images&#8221;</p>
<p><strong>from a view (application/views/scripts/controllerName/viewName.phtml):</strong></p>
<p><span style="color: #000000;"><span style="color: #ff0000;">&lt;?php</span> <span style="color: #ff6600;">$imgSrc</span> = <span style="color: #0000ff;">$this-&gt; ProductImageHelper</span>(<span style="color: #008000;">$this-&gt; products[$i]['products_image']</span>,<span style="color: #008000;"> &#8217;100&#8242;</span>);<span style="color: #ff0000;"> ?&gt;</span></span></p>
<p><span style="color: #000000;">&lt;img border=&#8221;0&#8243;  src=&#8221;<span style="color: #ff0000;">&lt;?php</span> echo <span style="color: #ff6600;">$imgSrc</span>; <span style="color: #ff0000;">?&gt;</span>&#8221; /&gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/zend-notes-grabbing-a-resource-from-the-registry-via-a-view-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>framework.zend.com &#8220;Create a Model and Database Table&#8221; tutorial fixed, full working code, adapted for MySQL</title>
		<link>http://alexyz.com/framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql</link>
		<comments>http://alexyz.com/framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 18:02:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=539</guid>
		<description><![CDATA[http://framework.zend.com/manual/1.10/en/learning.quickstart.create-model.html Well, I agonized over getting this, and if you read the comments on the tutorial, many others have as well, working on my home Snow Leopard as well as on my work XP pc, and I spent countless hours looking for a post just such as this one is now, to no avail, so [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://framework.zend.com/manual/1.10/en/learning.quickstart.create-model.html">http://framework.zend.com/manual/1.10/en/learning.quickstart.create-model.html</a></p>
<p>Well, I agonized over getting this, and if you read the comments on the tutorial, many others have as well, working on my home Snow Leopard as well as on my work XP pc, and I spent countless hours looking for a post just such as this one is now, to no avail, so here it all is, hope it helps somebody:</p>
<p><strong>hosts</strong></p>
<p>In the event that you don&#8217;t have this done already, here is what should go in your environment&#8217;s hosts file&#8230;</p>
<p>Mac: <span style="color: #800000;">/private/etc/hosts<br />
</span></p>
<p>PC:  <span style="color: #800000;">C:\WINDOWS\system32\drivers\etc</span></p>
<p># Setup &#8220;components&#8221; Virtual Host<br />
&lt;VirtualHost *:80&gt;<br />
ServerName <span style="color: #000000;"><strong>project</strong></span><br />
DocumentRoot &#8220;<span style="color: #800000;">C:\xampp\htdocs\<span style="color: #000000;">project</span>\public</span>&#8221; <span style="color: #800000;">// <strong><span style="color: #000000;">or</span></strong> /Library/WebServer/Documents/<span style="color: #000000;">project</span>/public</span></p>
<p>&lt;Directory &#8220;<span style="color: #800000;">C:\xampp\htdocs\<span style="color: #000000;">project</span>\public</span>&#8221; // <strong>or</strong> <span style="color: #800000;">/Library/WebServer/Documents/<span style="color: #000000;">project</span>/public</span>&gt;<br />
Options Indexes FollowSymLinks Includes<br />
AllowOverride All<br />
Order allow,deny<br />
Allow from all<br />
&lt;/Directory&gt;<br />
&lt;/VirtualHost&gt;</p>
<p><span style="color: #000000;"><strong>create the database that this will use</strong></span></p>
<p><span style="color: #800000;">CREATE TABLE IF NOT EXISTS `guestbook` (<br />
`id` int(11) NOT NULL AUTO_INCREMENT,<br />
`email` varchar(32) DEFAULT NULL,<br />
`comment` text,<br />
`created` datetime DEFAULT NULL,<br />
PRIMARY KEY (`id`)<br />
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;</span></p>
<p><span style="color: #000000;"><strong>add dummy data to the database</strong></span></p>
<p><span style="color: #800000;">INSERT INTO `guestbook` (`id`, `email`, `comment`, `created`) VALUES<br />
(1, &#8216;ralph@schindler.com&#8217;, &#8216;hello&#8217;, &#8217;2010-09-17 00:00:00&#8242;),<br />
(2, &#8216;foo@bar.com&#8217;, &#8216;goodbye&#8217;, &#8217;2010-09-17 00:00:00&#8242;);</span></p>
<p><strong>if you haven&#8217;t done so already, create the user this app will use to connect, and give the user the priviledges they&#8217;ll need</strong></p>
<p><span style="color: #800000;">CREATE USER &#8216;guestbook&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;guestbook&#8217;;</span></p>
<p><span style="color: #800000;">GRANT ALL ON &#8216;guestbook&#8217; TO &#8216;guestbook&#8217;@'localhost&#8217;;</span></p>
<p><strong><span style="color: #000000;">project/application/Bootstrap.php</span></strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap<br />
{<br />
public function _initAutoloader()<br />
{<br />
// Create an resource autoloader component<br />
$autoloader = new Zend_Loader_Autoloader_Resource(array(<br />
&#8216;basePath&#8217;    =&gt; APPLICATION_PATH,<br />
&#8216;namespace&#8217; =&gt; &#8216;Application&#8217;<br />
));</span></p>
<p>// Add some resource types<br />
$autoloader-&gt;addResourceTypes(array(<br />
&#8216;forms&#8217; =&gt; array(<br />
&#8216;path&#8217; =&gt; &#8216;forms&#8217;,<br />
&#8216;namespace&#8217; =&gt; &#8216;Form&#8217;<br />
),<br />
&#8216;models&#8217; =&gt; array(<br />
&#8216;path&#8217; =&gt; &#8216;models&#8217;,<br />
&#8216;namespace&#8217; =&gt; &#8216;Model&#8217;<br />
),<br />
));</p>
<p>// Return to bootstrap resource registry<br />
return $autoloader;<br />
}</p>
<p>protected function _initActionHelpers() <span style="color: #800000;"><br />
{<br />
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .&#8217;/helpers&#8217;);<br />
}</span></p>
<p>protected function _initDoctype() <span style="color: #800000;"><br />
{<br />
$this-&gt;bootstrap(&#8216;view&#8217;);<br />
$view = $this-&gt;getResource(&#8216;view&#8217;);<br />
$view-&gt;doctype(&#8216;XHTML1_STRICT&#8217;);<br />
}<br />
}</span></p>
<p><span style="color: #800000;"><span style="color: #000000;"><strong>project/public/index.php</strong></span></span></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
// Define path to application directory<br />
defined(&#8216;APPLICATION_PATH&#8217;)<br />
|| define(&#8216;APPLICATION_PATH&#8217;, realpath(dirname(__FILE__) . &#8216;/../application&#8217;));</span></p>
<p>// Define application environment<br />
defined(&#8216;APPLICATION_ENV&#8217;)<br />
|| define(&#8216;APPLICATION_ENV&#8217;, (getenv(&#8216;APPLICATION_ENV&#8217;) ? getenv(&#8216;APPLICATION_ENV&#8217;) : &#8216;development&#8217;));</p>
<p>// Ensure library/ is on include_path<br />
set_include_path(implode(PATH_SEPARATOR, array(<br />
realpath(APPLICATION_PATH . &#8216;/../library&#8217;),<br />
get_include_path(),<br />
)));</p>
<p>/** Zend_Application */<br />
require_once &#8216;Zend/Application.php&#8217;;</p>
<p>// Create application, bootstrap, and run<br />
$application = new Zend_Application(<br />
APPLICATION_ENV,<br />
APPLICATION_PATH . &#8216;/configs/application.ini&#8217;<br />
);<br />
$application-&gt;bootstrap()<br />
-&gt;run();</p>
<p><strong>project/application/configs/application.ini</strong></p>
<p><span style="color: #800000;">[production]<br />
phpSettings.display_startup_errors = 0<br />
phpSettings.display_errors = 0<br />
includePaths.library = APPLICATION_PATH &#8220;/../library&#8221;<br />
bootstrap.path = APPLICATION_PATH &#8220;/Bootstrap.php&#8221;<br />
bootstrap.class = &#8220;Bootstrap&#8221;<br />
appnamespace = &#8220;Application&#8221;<br />
resources.frontController.controllerDirectory = APPLICATION_PATH &#8220;/controllers&#8221;<br />
resources.frontController.params.displayExceptions = 0<br />
resources.view[] =<br />
resources.layout.layoutPath = APPLICATION_PATH &#8220;/layouts/scripts/&#8221;</span></p>
<p>resources.db.adapter = &#8220;PDO_MYSQL&#8221;<br />
resources.db.params.host = &#8220;localhost&#8221;<br />
resources.db.params.username = &#8220;guestbook&#8221;<br />
resources.db.params.password = &#8220;guestbook&#8221;<br />
resources.db.params.dbname = &#8220;guestbook&#8221;</p>
<p>[staging : production]</p>
<p>[testing : production]<br />
phpSettings.display_startup_errors = 1<br />
phpSettings.display_errors = 1</p>
<p>[development : production]<br />
phpSettings.display_startup_errors = 1<br />
phpSettings.display_errors = 1<br />
resources.frontController.params.displayExceptions = 1</p>
<p><strong>project/application/controllers/GuestbookController.php</strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class GuestbookController extends Zend_Controller_Action<br />
{</span></p>
<p>public function init() <span style="color: #800000;"><br />
{<br />
/* Initialize action controller here */<br />
}</span></p>
<p>public function indexAction() <span style="color: #800000;"><br />
{<br />
$guestbook = new Application_Model_GuestbookMapper();<br />
$guestbook-&gt;fetchAll();<br />
//var_dump($guestbook);<br />
$this-&gt;view-&gt;entries = $guestbook-&gt;fetchAll();<br />
}<br />
}</span></p>
<p><strong>project/application/models/Guestbook.php</strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Application_Model_Guestbook<br />
{<br />
protected $_comment;<br />
protected $_created;<br />
protected $_email;<br />
protected $_id;</span></p>
<p>public function __construct(array $options = null)<br />
{<br />
if (is_array($options)){<br />
$this-&gt;setOptions($options);<br />
}<br />
}</p>
<p>public function __set($name, $value) <span style="color: #800000;"><br />
{<br />
$method = &#8216;set&#8217; . $name;<br />
if ((&#8216;mapper&#8217; == $name) || !method_exists($this, $method)){<br />
throw new Exception(&#8216;Invalid guestbook property&#8217;);<br />
}<br />
$this-&gt;$method($value);<br />
}</span></p>
<p>public function __get($name) <span style="color: #800000;"><br />
{<br />
$method = &#8216;get&#8217; . $name;<br />
if ((&#8216;mapper&#8217; == $name) || !method_exists($this, $method)){<br />
throw new Exception(&#8216;Invalid guestbook property&#8217;);<br />
}<br />
return $this-&gt;$method();<br />
}</span></p>
<p>public function setOptions(array $options) <span style="color: #800000;"><br />
{<br />
$methods = get_class_methods($this);<br />
foreach($options as $key =&gt; $value){<br />
$method = &#8216;set&#8217; . ucfirst($key);<br />
if (in_array($method, $methods)){<br />
$this-&gt;$method($value);<br />
}<br />
}<br />
}</span></p>
<p>public function setComment($text) <span style="color: #800000;"><br />
{<br />
$this-&gt;_comment = (string) $text;<br />
return $this;<br />
}</span></p>
<p>public function getComment() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_comment;<br />
}</span></p>
<p>public function setEmail($email) <span style="color: #800000;"><br />
{<br />
$this-&gt;_email = (string) $email;<br />
return $this;<br />
}</span></p>
<p>public function getEmail() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_email;<br />
}</span></p>
<p>public function setCreated($ts) <span style="color: #800000;"><br />
{<br />
$this-&gt;_created = $ts;<br />
return $this;<br />
}</span></p>
<p>public function getCreated() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_created;<br />
}</span></p>
<p>public function setId($id) <span style="color: #800000;"><br />
{<br />
$this-&gt;_id = (int) $id;<br />
return $this;<br />
}</span></p>
<p>public function getId() <span style="color: #800000;"><br />
{<br />
return $this-&gt;_id;<br />
}<br />
}</span></p>
<p><strong><span style="color: #800000;"><span style="color: #000000;">project/application/models/GuesbookMapper.php</span></span></strong></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Application_Model_GuestbookMapper<br />
{<br />
protected $_dbTable;</span></p>
<p>public function setDbTable($dbTable) <span style="color: #800000;"><br />
{<br />
if (is_string($dbTable)){<br />
$dbTable = new $dbTable();<br />
}<br />
if (!$dbTable instanceof Zend_Db_Table_Abstract){<br />
throw new Exception(&#8216;Invalid table data gateway provided&#8217;);<br />
}<br />
$this-&gt;_dbTable = $dbTable;<br />
return $this;<br />
}</span></p>
<p>public function getDbTable() <span style="color: #800000;"><br />
{<br />
if (null === $this-&gt;_dbTable){<br />
$this-&gt;setDbTable(&#8216;Application_Model_DbTable_Guestbook&#8217;);<br />
}<br />
return $this-&gt;_dbTable;<br />
}</span></p>
<p>public function save(Application_Model_Guestbook $guestbook) <span style="color: #800000;"><br />
{<br />
$data = array(<br />
&#8216;email&#8217;    =&gt;    $guestbook-&gt;getEmail(),<br />
&#8216;comment&#8217;    =&gt;    $guestbook-&gt;getComment(),<br />
&#8216;created&#8217;    =&gt;    date(&#8216;Y-m-d H:i:s&#8217;),<br />
);</span></p>
<p>if (null === ($id = $guestbook-&gt;getId())){ <span style="color: #800000;"><br />
unset($data['id']);<br />
$this-&gt;getDbTable()-&gt;insert($data);<br />
} else {<br />
$this-&gt;getDbTable()-&gt;update($data,array(&#8216;id = ?&#8217; =&gt; $id));<br />
}<br />
}</span></p>
<p>public function find($id, Application_Model_Guestbook $guestbook) <span style="color: #800000;"><br />
{<br />
$result = $this-&gt;getDbTable()-&gt;find($id);<br />
if (0 == count($result)){<br />
return;<br />
}<br />
$row = $result-&gt;current();<br />
$guestbook-&gt;setId($row-&gt;id)<br />
-&gt;setEmail($row-&gt;email)<br />
-&gt;setComment($row-&gt;comment)<br />
-&gt;setCreated($row-&gt;created);<br />
}</span></p>
<p>public function fetchAll() <span style="color: #800000;"><br />
{<br />
$resultSet = $this-&gt;getDbTable()-&gt;fetchAll();<br />
//var_dump($resultSet);<br />
$entries = array();<br />
foreach ($resultSet as $row){<br />
$entry = new Application_Model_Guestbook();<br />
$entry-&gt;setId($row-&gt;id)<br />
-&gt;setEmail($row-&gt;email)<br />
-&gt;setComment($row-&gt;comment)<br />
-&gt;setCreated($row-&gt;created);<br />
$entries[] = $entry;<br />
}<br />
return $entries;<br />
}<br />
}</span></p>
<p><span style="color: #000000;"><strong>project/application/models/DbTable/Guestbook.php</strong></span></p>
<p><span style="color: #800000;"><span style="color: #ff0000;">&lt;?php</span><br />
class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract<br />
{<br />
/** Table name */<br />
protected $_name    = &#8216;guestbook&#8217;;<br />
}</span></p>
<p><span style="color: #800000;"><strong><span style="color: #000000;">project/application/views/scripts/guestbook/index.phtml</span></strong></span></p>
<p><span style="color: #800000;">&lt;p&gt;&lt;a href=&#8221;<span style="color: #ff0000;">&lt;?php</span> echo $this-&gt;url(<br />
array(<br />
&#8216;controller&#8217; =&gt; &#8216;guestbook&#8217;,<br />
&#8216;action&#8217; =&gt; &#8216;sign&#8217;<br />
),<br />
&#8216;default&#8217;,<br />
true) <span style="color: #ff0000;">?&gt;</span>&#8220;&gt;Sign Our Guestbook&lt;/a&gt;&lt;/p&gt;</span></p>
<p>Guestbook Entries: &lt;br /&gt; <span style="color: #800000;"><br />
&lt;dl&gt;<br />
<span style="color: #ff0000;">&lt;?php</span> foreach ($this-&gt;entries as $entry): <span style="color: #ff0000;">?&gt;</span><br />
&lt;dt&gt;<span style="color: #ff0000;">&lt;?php</span> echo $this-&gt;escape($entry-&gt;email) <span style="color: #ff0000;">?&gt;</span>&lt;/dt&gt;<br />
&lt;dd&gt;<span style="color: #ff0000;">&lt;?php</span> echo $this-&gt;escape($entry-&gt;comment)<span style="color: #ff0000;">?&gt;</span>&lt;/dd&gt;<br />
<span style="color: #ff0000;">&lt;?php</span> endforeach <span style="color: #ff0000;">?&gt;</span><br />
&lt;/dl&gt;</span></p>
<p><strong><span style="color: #000000;">final URL to hit: <span style="color: #000080;">http://<span style="color: #000000;">project</span>/guestbook</span></span></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/framework-zend-com-create-a-model-and-database-table-tutorial-fixed-full-working-code-adapted-for-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP htaccess file serve script</title>
		<link>http://alexyz.com/php-htaccess-file-serve-script/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-htaccess-file-serve-script</link>
		<comments>http://alexyz.com/php-htaccess-file-serve-script/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 18:34:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://alexyz.com/?p=339</guid>
		<description><![CDATA[search this blog for the &#8220;htaccess&#8221; file contents to put in a directory, then use this to serve up pdf files securely from said directory: file serve php script: first check Zend permissions&#8230;logged in, permissions granted, user active, expirations, etc&#8230;.. then: &#60;? $file = &#8220;path/path/&#8221; . $_GET['file']; //$file = &#8220;Broker_Admin/Materials/Course.pdf&#8221;; header(&#8216;Content-type: application/pdf&#8217;); header(&#8220;Content-Disposition: inline; filename=&#8221;.$file); [...]]]></description>
			<content:encoded><![CDATA[<p>search this blog for the &#8220;htaccess&#8221; file contents to put in a directory, then use this to serve up pdf files securely from said directory:</p>
<p>file serve php script:</p>
<p>first check Zend permissions&#8230;logged in, permissions granted, user active, expirations, etc&#8230;..<br />
then:</p>
<p>&lt;?<br />
$file = &#8220;path/path/&#8221; . $_GET['file'];<br />
//$file = &#8220;Broker_Admin/Materials/Course.pdf&#8221;;<br />
header(&#8216;Content-type: application/pdf&#8217;);<br />
header(&#8220;Content-Disposition: inline; filename=&#8221;.$file);<br />
/*header(&#8220;Content-Disposition: attachment; filename=&#8221;.$file);*/<br />
header(&#8216;Last-Modified: &#8216;.gmdate(&#8216;D, d M Y H:i:s&#8217;) . &#8216; GMT&#8217;);<br />
header(&#8216;Cache-Control: no-store, no-cache, must-revalidate&#8217;);<br />
header(&#8216;Cache-Control: pre-check=0, post-check=0, max-age=0&#8242;);<br />
header(&#8216;Pragma: anytextexeptno-cache&#8217;, true);<br />
header(&#8216;Cache-control: private&#8217;);<br />
header(&#8216;Expires: 0&#8242;);<br />
readfile($file);<br />
?&gt;</p>
<p>then from wherever I want to call it I call this script and pass in the file wanted.</p>
<p>like this:</p>
<p>&lt;a href=&#8221;file_serve.php?file=Test.pdf&#8221;&gt;Download the Test file here&lt;/a&gt;</p>
<p>File is NOT accessible directly, or via this script since it first checks visitor&#8217;s SESSIONS, ZEND Permissions, that variables passed to it are set, etc. and so on&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://alexyz.com/php-htaccess-file-serve-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

