August 23rd, 2009
There are many articles around explaining Zend_Acl and how to use it within a CMS like system where generic roles apply - i.e. an admin can do anything, a guest can leave a comment and an author can write articles. But I was having a hard time figuring out how to elegantly enforce user specific permissions in addition to generic permissions For example, an author can save a new article, but can only update or delete an article that they “own”. I was trying to use assertions, but the role object in the assertion was turned into a generic Zend_Acl_Role object, even though I was using my own role object that implemented Zend_Acl_Role_Interface. Therefore, I couldn’t check the userId of the role in the assertion and was trying to pass responsibility back onto the object that was checking the acl.
It looks like this has all been fixed in 1.9.1, and Ralph does a good job of explaining the details. I have yet to try the improvements, but looking forward to refactoring my code to use the new and improved assertions.
Posted in PHP, Zend Framework | 1 Comment »
July 7th, 2009
I signed up for a VPS on Slicehost today, and am very impressed. The interface is refreshingly basic and I was up and running in no time. Their articles are absolutely amazing, and worth the read even if you don’t use their services. I know Ubuntu somewhat, but am far from an expert. Using the Ubuntu set up guide, I was up and running in under an hour. I made a stupid mistake when copying my public key and had to rebuild my slice. But that’s the beauty of the cloud, just hit a button, start with a fresh install and go again.
I am testing it out, as I have a dedicated server which costs too much for the small number of low traffic sites I maintain. After going through all the articles on getting the basics set up, I altered my /etc/hosts file on my desktop to point to the IP address of my new slice, updated the ServerAlias in the Apache vhosts file to include the “slice” domain name in my /etc/hosts file, and then finally enabled mod_rewite (sudo a2enmod rewrite) so I could test out a site that was running Zend_Framework without having to actual point production traffic at it.
I then set up rysnc and get some database permission set up and tables copied over, and it was live. Talk about easy….
I looked at Amazon, and while it offers a lot of flexibility and they are developing more and more tools (instead of APIs), it just seemed like way to much work for my limited needs. Anyways, really impressed with Slicehost after just one day, we’ll see how it goes in the next week or so. This blog may be moving over next…
Posted in PHP, Linux | 2 Comments »
May 28th, 2009
Using Zend_Http_Client to make a simple REST GET request to a web service and the body of the response I got back was completely mangled – i.e. the characters were not even remotely readable. That’s strange I thought, and pasted the url in my browser and it came back fine. Looking at the response headers, I saw the content encoding was gzip ([Content-encoding] => gzip), which made sense as my browser would uncompress the response, while PHP would not automatically do that.
Rather than trying to uncompress the response, I modified the request header to not accept gzip and it came back un-encoded and ready to use in PHP:
<?php
$client = new Zend_Http_Client($url);
$client->setHeaders(array(‘Accept-encoding’ => ‘’));
$response = $client->request();
print_r($response);
?>
Posted in PHP, Zend Framework | No Comments »
May 22nd, 2009
I am utilizing Zend_Service_Technorati to tag search and when I return the results and loop through it via a partialLoop, an exception is thrown occasionally. One of the results does not have a valid uri and Zend_Uri_Http is throwing the exception based on the path (not sure whether Tehnorati is returning a invalid url or Zend_Uri_Http is declaring a valid url invalid). The problem is I am using partialLoop to dynamically loop through result sets other than Technorati, such as Youtube and Flickr, and it is nice just to call the appropriate partial based on the result set object.
However, there is no easy way to catch the Exception. If I wrap the entire partial loop in a try/catch, then it doesn’t display any results when there is an exception, even though there is only one offending result:
<?php
try {
echo $this->partialLoop(‘adminexternalmedia/_result’ . $this->collection->type . ‘.phtml’,$this->resultSet);
} catch(Exception $e) {
echo ‘problem’;
}
?>
I can’t catch the exception in the partial that handles the display, because the exception is created once the individual result is grabbed from the set and before the partial is “rendered” - i.e. triggered in the foreach call. Since the result sets implement SeekableIterator, I can use a while loop and call partial, instead of relying on the partialLoop, and handle my exception as I deem fit:
<?php
$this->partial()->setObjectKey(‘model’);
while($this->resultSet->valid()) {
try {
$result = $this->resultSet->current();
echo $this->partial(‘adminexternalmedia/_result’ . $this->collection->type . ‘.phtml’,$result);
} catch (Exception $e) {
echo ‘problem<br /><br />’;
}
$this->resultSet->next();
}
?>
Posted in PHP, Zend Framework | No Comments »
May 2nd, 2009
Querying Youtube for videos via Zend_Gdata and ran into memory issues when searching for up to 20 videos. It was a simple fix, just had to up my memory_limit in php.ini. It was at 8M and I set it to 12M and am not running into any more issues. If you are on a shared hosting environment, you can use init_set within the page:
<?php
ini_set(“memory_limit”,“12M”);
?>
Just be careful what you set it to, as too high a limit could cause problems.If you have a page that consumes a lot of memory and you set it high, say 50M, and along comes something that requests the page a lot, maybe a search spider gone bad or malicious user, you could run out of memory on your server…
Posted in PHP, Zend Framework | No Comments »