This just came up on #zftalk, and it appears that the information out there is either incomplete or incorrect, so I thought I’d just put out a simple solution. Here’s a simple way to calculate the difference between two Zend_Date objects (in days):
$jan1 = new Zend_Date('1.12.2009', Zend_Date::DATES);
echo "\nJanuary first: ", $jan1->toString();
$christmas = new Zend_Date('25.12.2009', Zend_Date::DATES);
echo "\nChristmas is on: ", $christmas->toString();
$diff = $christmas->sub($jan1);
echo "\nNumber of days: ", $diff / 60 / 60 / 24;
I’ve been thinking a lot about Modeling in a MVC application, particularly in the Zend Framework. Obviously each application is different, and any Model is going to be fairly unique to your application. That’s why ZF doesn’t provide a base Model class. That said, there are some design patterns that a lot of people are using nowadays, and applications could use some base functionality to facilitate those patterns.
Zend Framework’s project lead, Matthew Weier O’Phinney, has a lot of great thoughts about Modeling that I’ve been trying to stick to. In implementing those ideas, I’ve started thinking out some base classes to build my Models on top of. Obviously these classes won’t work for everyone. But they should work for a lot of “typical” web applications.
For some reason this took me a long time to figure out, so I thought I’d post it in case other people are having similar problems. I wanted www.mysite.com to route to the www module and app.mysite.com to route to the app module. In the end it was quite simple—I was trying to make it much more complicated than it needed to.
I’m using Zend Framework 1.8.4 with Zend_Application
Here’s my router configuration:
resources.router.routes.www.type = "Zend_Controller_Router_Route_Hostname" resources.router.routes.www.route = ":module.mysite.com" resources.router.routes.www.defaults.module = "www" resources.router.routes.www.chains.index.type = "Zend_Controller_Router_Route" resources.router.routes.www.chains.index.route = ":controller/:action/*" resources.router.routes.www.chains.index.defaults.controller = "index" resources.router.routes.www.chains.index.defaults.action = "index"
And here’s my .htaccess rule that redirect to www if another subdomain is used (or no subdomain is given):
RewriteCond %{HTTP_HOST} !^(www|app)\.mysite\.(com|local)
RewriteRule ^(.*)$ http://www.mysite.%2/$1 [R=302,QSA,L]Otherwise it’s just your standard modular structure generated with the zf tool.
This post is mostly a reminder to myself, but I thought I’d put it out there just in case other people wanted some help:
If Zend Server is already installed, you need to remove it:
/Applications/ZendServer/bin/zendctl.sh stop/etc/zce.rcps ax|grep -i zend)/usr/local/zend/bin/uninstall.shNow download the latest version of the Zend Server CE Installer and run the installer
Link the CLI binary so you can use PHP from the command line:
sudo ln -s /usr/local/zend/bin/php-cli /usr/bin/phpNow download the latest version of the Zend Framework
Unzip and copy the following files:
library/Zend to /usr/local/zend/share/ZendFramework/library/Zendextras/library/ZendX to /usr/local/zend/share/ZendFramework/library/ZendXbin to /usr/local/zend/share/ZendFramework/binzf command line tool, and the version of the Zend Framework that came with Zend Server is up-to-date, these steps are unnecessaryFinally, link the zf.sh file so you can access it easily:
sudo ln -s /usr/local/zend/share/ZendFramework/bin/zf.sh /usr/bin/zfThat’s it for now. Hope that helps someone else out.
Recent Comments