Assuming you’re using the method demonstrated in the Zend Framework Manual, the first thing you need is to configure the Zend AutoLoader. Add this to the index.php file in your public directory:
// Configure autoloader
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
// Require Smarty Engine
require_once 'Smarty/Smarty.class.php'; // Assuming that you have the Smarty engine at "library/Smarty"
$autoloader->pushAutoloader('Smarty', 'smartyAutoload');
Change the following line in “Smarty/Smarty.class.php” (about line 91) from this:
if (set_include_path(SMARTY_SYSPLUGINS_DIR . PATH_SEPARATOR . get_include_path()) !== false) {
To this:
if (!class_exists('Zend_Loader_Autoloader') && set_include_path(SMARTY_SYSPLUGINS_DIR . PATH_SEPARATOR . get_include_path()) !== false) {
Next, comment out the line in the Smarty Constructor (about line 237):
//$this->template_dir = array('.' . DS . 'templates' . DS);
We want to keep it a null value (which is the default). If we don’t make this change in the constructor (mentioned just above), we’ll get PHP Notices that Zend_Controller_Action_Helper_ViewRenderer tried to convert an array to a string.
Finally, add this to your bootstrapper class:
protected function _initView()
{
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(‘ViewRenderer’);
$view = new Zend_View_Smarty();
$viewRenderer->setView($view)
->setViewScriptPathSpec(APPLICATION_PATH . ‘/views/scripts/:controller/:action.:suffix’)
->setViewSuffix(‘tpl’);
}
If you’re using modules, you might want to make a slight change to the setViewScriptPathSpec method:
setViewScriptPathSpec(APPLICATION_PATH . ‘/modules/:module/views/scripts/:controller/:action.:suffix’);
You should be good to go. I should mention that this will cause your layouts to be parsed via Smarty as well; which presents its own problems. A potential work around is to include a common header and footer for each individual template, although this is far from ideal. In that case, what you might want to do is disable the view renderer’s auto render feature and create a custom plugin or action helper that will render the templates and layouts. I’m considering expounding on this in another post…
Recently I went through and upgraded a website from Zend Framework 1.7 to the latest 1.9 minor version. Everything worked great for the most part (aside from a minor code change involving Zend Filter for requests), but there was one significant change that was a bit of a hassle to fix (i.e. “File not found” and “directory listings prohibited” Apache errors).
One of the major changes since 1.7 is the functionality of the Zend Framework class AutoLoader. In previous versions of Zend Framework all you had to do was instantiate the AutoLoader and the classes would magically load as needed. But now it’s not quite so simple. The rationale, and it’s quite good, for the change can be read about in this Zend devzone article.
It’s important to mention at this point that if, for examle, your “IndexController” inherits directly from “Zend_Controller_Action”, you will not need to do any of this because in that scenario, you should not have any of these issues. These hurdles are only applicable if you extend the Zend Framework classes with your own.
Moving on… Instead of just instantiating the AutoLoader, you must now declare all namespaces that will be used throughout your application. For example, in your application controllers directory you might have a class named “BlogController.php” and your class would be named something like “IndexController” which extends a custom controller in the library that looks like “Blog_Controller_Action” and that class would extend “Zend_Controller_Action”. The AutoLoader knows where to find “Zend_Controller_Action”, but it doesn’t know where to look for “Blog_Controller_Action”. There are two solutions to this problem.
The easy answer is you to add the “$autoloader->setFallbackAutoloader(true);” function call, but this is kind of hack. In addition, using the Zend Framework default loader as a fallback means that every request to your site will result in an error, and then Zend Framework will try to use the default loader to resolve the request. This means extra load time and extra stress on the server. Granted, there is an “$autoloader->suppressNotFoundWarnings(true);” function, but it doesn’t work the way you think. Read more about the default autoloader on the Zend Framework manual here.
The correct solution to this problem is to declare all your namespaces and instantiate a unique AutoLoader for your models and controllers. For example:
// Set up autoload.
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
// Just in case there's something we missed, we can leave the fallback
// Add resource loader, otherwise "file not found" errors are raised
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => '../library/Blog/',
'namespace' => 'Blog',
'resourceTypes' => array(
'model' => array(
'path' => 'model/',
'namespace' => 'Model',
),
'controller' => array(
'path' => 'controller/',
'namespace' => 'Controller'
)
)
));
$autoloader->pushAutoloader($resourceLoader);
You can read all the details here. It’s quite a change from the simplicity before, but it’s a good change.
In addition, you’ll need to make sure to update your .htaccess to the following or else you’ll get a bunch of “Directory indexes prohibited by server configuration” errors:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
This also has been modified and improved over previous versions, for one, it loads Flash files (and other non-standard extensions) without a problem. Strangely, I didn’t see the .htacces directives in the Zend Quickstart tutorial, but it is in the Zend Framework’s manual Application Quickstart. The page names are similar but they are completely different.
In summary, until we made the changes mentioned above to our Zend Framework configuration our Apache error log was riddled with thousands of “File not found” and “Directory indexes forbidden” errors. The AutoLoader change resolved the “file not found” errors, and the .htaccess update resolved the “Directory indexes forbidden” errors. Hope this was useful.
I’ve done this a few times already, and it seems every time I make the same time-wasting mistakes. So here’s the process quick and dirty (be sure to follow the links if there’s a point you don’t understand or know how to do):
If you’ve never used Zend Framework before, you may want to follow along with the Quickstart from here.
If you’re going to using Flash, make sure to make the change in the .htaccess I mention here. Also, if you plan on uploading images at some point and would like MIME type validation and/or file information you’ll need to install the PECL fileinfo extension as explained by Jeffrey Barke on his website.
That’s it. Kind of a pain since you have to do this every time you set up a new site (domain or subdomain), granted you could probably put the framework higher in the operating system and just link to it, but that has it’s own problems (i.e. framework version support/maintenance) and it wouldn’t save you any steps. Anyway, hope this is as useful to someone else as I know it will be to me.
Jack Doyle is a genius (Grant Skinner also deserves mention, a genius in his own right). TweenLite (and TweenMax, and TweenNano, and Tween…) proves, yet again, that it is the best ActionScript tweening engine in the world. I haven’t been this excited about a tweening engine in a while. Check out the new features of TweenLite!
Funniest thing I’ve seen in a while: http://www.flickr.com/photos/robotjohnny/3629069606/sizes/l/
Zend Framework 1.7 has been released!
Here’s what I’m excited about:
19 Nov
Posted by: eingko in: Browsers, Flash, Javascript, XHTML/CSS
I ran into a rather annoying issue the other day related to content alignment in Flash; as usual, this problem exists exclusively in Internet Explorer. To be more specific, it is an issue with how the Flash Player ActiveX control is written.
If you are aligning content in Flash that uses the Stage width or height as a variable (e.g., you want to center a MovieClip) and you do it on initialization (i.e., in code and on the first frame), you may run in to this issue. Here is an image demonstrating what you might see:

Note that in the “before” screen, the content is centered horizontally, while in the “after” screen, the content is only half-visible and appears to be “centered” on the left margin.
If you run a test – output the Stage width to a text field, you’ll see that the width will be returned as 0.
As far as I know, there are two solutions to this problem. If you’re embedding your Flash using swfObject, then make sure that you omit the “scale” attribute. For example, modify the following:
var params = {
bgcolor: "#000000",
menu: "false",
scale: "noScale",
allowFullScreen: true
};
To something that looks like this:
var params = {
bgcolor: "#000000",
menu: "false",
allowFullScreen: true
};
Alternatively, if you absolutely need that attribute. You can create an “EnterFrame” event listener that detects when the Stage width is greater than 0 and then remove the listener. Here’s an example in ActionScript 2:
this.onEnterFrame = function() {
if (Stage.width > 0) {
init(); // Pass to initialization function
this.onEnterFrame = null; // Clear enterFrame listener
}
}
Parse error: syntax error, unexpected ‘)’, expecting T_PAAMAYIM_NEKUDOTAYIM in …
I encountered this weird PHP error today; if it happens to you it’s probably because you forgot to declare a variable by leaving off the ‘$’ prefix (e.g., ‘myVar’ instead of ‘$myVar’). More info here: http://en.wikipedia.org/wiki/Paamayim_Nekudotayim.
Obviously, it’s a fairly cryptic error message; albeit its cause is simple to resolve. It is exactly these types of things that makes it easier to understand why so many developers dislike PHP – it doesn’t keep me from using it though.
Here’s a quick little “gotcha” when using the Zend PHP Framework:
If you plan on using Flash at all (i.e., SWF or FLV files) be sure to append the necessary extensions the .htaccess file in the “public” folder to the rewrite rule:
RewriteEngine On RewriteRule !\.(js|ico|gif|jpg|png|css|swf|flv)$ index.php
Note the added “swf” and “flv” extensions. Otherwise access to these files will return an error. Firebug (if you use it) will say that the files are being loaded (200 OK), but if you look at the response, it’s the error page not the actually requested file that is being returned.
Granted, this isn’t exclusive to the Zend Framework – it’s a result of the .htaccess configuration (regardless of which framework/engine you use); but it’s just something to keep in mind.
Update:
Here’s a better declaration (via: http://framework.zend.com/manual/en/zend.application.quick-start.html):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Here’s a “heads up” to anyone who may be pulling his/her hair out wondering why NetStream won’t load an FLV. For whatever reason (I’m guessing it’s a bug), if you have a strongly-typed NetStream within a function, it will not work.
For example, the following code will work on “_root”:
var my_video:Video; // my_video is a Video object on the Stage
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("video1.flv");
Try dropping this into a function or class and you will see that it does not work at all. To make it work, you must completely remove the data typing and variable declaration for the NetStream and NetConnection:
var my_video:Video; // my_video is a Video object on the Stage
my_nc = new NetConnection();
my_nc.connect(null);
my_ns = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("video1.flv");
See Adobe’s LiveDocs on this topic for more information.
I wasted far too many hours trying to figure this out thinking that the problem was with my code. I hope I can save someone else from the same frustration.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Nov | ||||||
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |