Sound Doesn't Work Kubuntu 9.10 with PulseAudio

It seems like every time I upgrade Kubuntu, my sound doesn't work anymore. I guess "doesn't work" isn't the right term. It seems that the output is muted. If I type pavucontrol into the command line and then go to output devices on the volume control window that pops up, the Internal Audio Analog Stereo is muted. I don't know why the pulse audio volume control is defaulting to that setting every time I upgrade, but I fiddled around with my sound settings a couple of years ago when I was having issues and that's likely the culprit. I think I need to do a fresh install one of these days....

Posted In: Uncategorized, Ubuntu | No Comments

Zend_Auth and more than one record matches the supplied identity

The Zend_Auth Db adapter will fail if you have more than one record returned, which makes sense. However, when I have coded something like this in the past, I would check how many records were returned with a matching username and password. Zend_Auth looks at how many records are returned for the username field regardless of whether the password matches, so you need to have a unique username field. I was trying to use a person's last name and password to authenticate, but obviously people had the same last name, so it was failling.

Posted In: Zend Framework | 3 comments

Setting up a new Site with Zend Framework Application/Tool

It's been awhile since I had to set up a new site with Zend Framework, and I took the chance to play around with Zend_Tool_Project. Following the QuickStart guide, I had a site up and running in no time. But it did take me a little while to figure out how to get my modules and custom library working with the site.

Modules

To get modules enabled, you first need to create a module with Zend_Tool_Project, or you can manually create a modules directory and add the module folder there. If I wanted to add a module called cms, I would create application/modules/cms or use the command line zf create module cms.

Then, In application.ini, you need to add the following two lines:
resources.modules[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

Finally, in order to load models and views, you need to add a Bootstrap.php file in the root of the modules - i.e. application/modules/cms/Bootstrap.php. In the module Bootstrap.php, place the following:
[php]
class Cms_Bootstrap extends Zend_Application_Module_Bootstrap
{
}
[/php]

You should be all set with modules now. Models you create within the module will use the naming convention of Cms_Model_Foo and controllers will be Cms_IndexController (when using Zend_Tool_Project and issuing zf create controller index index-action-included=1 cms, it names the controller class IndexController instead of Cms_IndexController?)

Autoloading Custom Library


The last thing I needed was to autoload my personal library which uses the naming convention Bolton_. My custom library resides in the same folder as the Zend library and is within my include path set in php.ini. In application.ini, you need to add the following line:
autoloaderNamespaces[] = "Bolton_"

Posted In: Zend Framework | No Comments

Zend_Service_Technorati and Connection Errors

I had a site that uses Technorati's API via Zend Framework- e.g. Zend_Service_Technorati. I noticed I am getting TCP connection errors via an exception (Message: Unable to Connect to tcp://api.technorati.com:80. Error #111: Connection refused), and upon going to Technorati's site to look at the API, I found out the new API is under works and the old API is available until October 25th, 2009. It is November 3rd, the old API apparently doesn't work and the new API isn't released. Really? Am I missing something here? TCP connection failing tells me they are rejecting completely rejecting the TCP connection, which leads me to believe they have shut off the API. Searching on Twitter confirms this, although having an existing key doesn't seem to matter...

Posted In: Zend Framework | 3 comments

PHPUnit and Mock Object Exactly Method

[php]
$mapper->expects($this->exactly('2'))->method('delete');
$mapper->expects($this->exactly(2))->method('delete');
[/php]
The two above lines of code don't behave the same. When passing in 2 as a string instead of a number, PHPUnit declares it a failure:

Em_Model_Collection_MapperTest::testDeleteCollectionWithJoinTable
Expectation failed for method name is equal to when invoked 2 time(s).
Method was expected to be called 2 times, actually called 2 times.

Posted In: PHP | No Comments

MooTools, form send function and b.lastIndexOf is not a function error

I am new to MooTools and was using MooTools 1.2.3 to submit a form via Ajax - pretty standard stuff. When trying to put in callbacks for onSuccess,onRequest, etc... I kept getting JavaScript errors (b.lastIndexOf is not a function). Looks like you need to use set() function first, then call send(). MooTools must have been updated, because there are a lot of examples on the intraweb that do not do this, but work in my browser. To add to my confustion, you can call send() on the form without set first as long as you don't pass an object with callbacks as a parameter in send().
This works
            window.addEvent('domready', function() {
$('myForm').addEvent('submit',function(event) {
event.preventDefault();
this.send();
})
});

This does not work

window.addEvent('domready', function() {
$('myForm').addEvent('submit',function(event) {
event.preventDefault();
this.send({onComplete:function(){alert('this');}});
})
});

This works with callbacks

window.addEvent('domready', function() {
$('myForm').addEvent('submit',function(event) {
event.preventDefault();
this.set('send',{onComplete:function(){
alert('this');
}
}).send();
})
});

Anyways, after a day of playing with MooTools, I have say I am impressed. Not sure why, but I think this is my favorite framework. I can't say I have much experience with JS frameworks, and my JavaScript is pretty bad these days, but I am impressed with MooTools so far.

Posted In: Uncategorized, JavaScript | No Comments

symlink with FTP

Apparently you can't use FTP for symlinks? It's been so long since I have mucked around with FTP, that I didn't realize you could not create symlinks. I have an old site I still maintain and had to move it to a new hosting provider and the new provider did not give SSH access (well at least without charging for it). PHP to the rescue:
[php]
symlink('../gallery','gallery');
[/php]
Use the symlink command in PHP. Obviously you need to have the proper permissions, and since PHP may be running as a different user, your mileage may very. But it worked for me...

Posted In: PHP, Linux | 2 comments

Zend_Acl with User Specific Permissions

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

Slicehost VPS

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

Zend_Http_Client and Garbled Response Body

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);
[/php]

Posted In: PHP, Zend Framework | 1 comment