Poedit and phtml files giving error from xgettext

Posted by & filed under Zend Framework.

Poedit Parse PHP

Problem

I had just set up a Poedit for a project at work and was trying to update the *.po file with new translations. It wasn’t finding a whole load of them.

After a while of poking around, it dawned on me that it was not looking in my phtml files. Simple enough, I just added *.phtml to the list of extensions in the parsers preference.

Then I receive a big long error message that xgettext didn’t know what phtml.

Solution

Add pthtml to your list of extensions

*.php;*.phtml

You also need to add ” -L php” to the end of your Parser command

xgettext --force-po -o %o %C %K %F -L php

PHP SimpleXmlElement values into an array

Posted by & filed under Zend Framework.

I have an XML string I was trying to parse for some values. The following XML was stored in a variable $xml




C3399
Lion's Paw Shell Pendant
Active
1
20.59

I used this to get to the values into an array.

$xmlObj = new SimpleXMLElement($xml);
$item = $xmlObj->children(‘ns0′, TRUE);
$data = array();

$data['Style'] = $item->Style;
$data['Status'] = $item->Status;
$data['Qty_Avail'] = $item->Quantity_Available;
$data['Price'] = $item->Wholesale_Price;

But when I did a print_r(data);, I would get this junk.

Array
(
[Style] => SimpleXMLElement Object
(
[0] => C3399
)

[Status] => SimpleXMLElement Object
(
[0] => Active
)

[Qty_Avail] => SimpleXMLElement Object
(
[0] => 1
)

[Price] => SimpleXMLElement Object
(
[0] => 20.59
)

)

But for testing if I just did a print $item->Style it would print just the value C3399

Then I ran across this little advice “You should cast elements to a float (or even string) if you plan on using them…” That made all the difference. So now my code has the (string) casting.

$xmlObj = new SimpleXMLElement($xml);
$item = $xmlObj->children(‘ns0′, TRUE);
$data = array();

$data['Style'] = (string)$item->Style;
$data['Status'] = (string)$item->Status;
$data['Qty_Avail'] = (string)$item->Quantity_Available;
$data['Price'] = (string)$item->Wholesale_Price;

Now I get a nice array, like I was expecting.

Array
(
[Style] => C3399
[Status] => Active
[Qty_Avail] => 1
[Price] => 20.59
)

Resources:
http://www.php.net/manual/en/class.simplexmlelement.php

Zend_Loader_PluginLoader_Exception

Posted by & filed under Zend Framework.

For the top alerts you get after you’ve saved a page or some other event, there is the built in Flashmessenger in Zend Framework, but emanaton has put together a great messenger called PriorityMessenger.

I had it running on one of my sites without issue, but when I tried to get it running on another site I get an error of.

I had placed my PriorityMessenger.php file in:
application/views/helpers/PriorityMessenger.php

Then when I tried to access the a controller I received.

Plugin by name 'PriorityMessenger' was not found in the registry; used paths:
Zend_View_Helper_Navigation_: Zend/View/Helper/Navigation/
Support_View_Helper_: /var/www/production/application/modules/support/views/helpers/
Zend_View_Helper_: Zend/View/Helper/

I checked the paths, the class names, etc. still no dice.

A Simple solution

In the application.ini file I added this line:


resources.view.helperPath = APPLICATION_PATH "/views/helpers"

This I guess tells Zend Framework to look in application/views/helpers for helpers applicable to all modules.

Keep up, keeping up.

PDO_Mysql error with Zend Server and socket

Posted by & filed under Zend Framework.

I’ve headed this issue off before, but now I think I know why it happens.

The problem

With a new install of Zend Server on my Mac and trying to access a DB with my Zend Framework web app I am greeted with an error of


Message: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" when trying to run our application.

This was rather frustrating as I changed all instances of mysql_default_socket in the PHP settings (php.ini). It still didn’t pick up the location of the socket. Since I’m using PDO, it looks like this is an issue in PHP 5.2 for PDO.

http://forums.zend.com/viewtopic.php?f=44&t=568

The work around for me has been to declare the socket in my application.ini file


resources.db.params.unix_socket = "/usr/local/zend/mysql/tmp/mysql.sock"

The problem this introduces, haveing a different application.ini on the server and on then on my local devel machine.

Ugggg.

Magento built on Zend Framework

Posted by & filed under Zend Framework.

Deeper and deeper into the Magento core I’ve plunged. It’s built on the Zend Framework. I’ve also been getting acquainted with Zend, with it you can quickly write powerful web applications that can do just whatever you can dream up. Many Google services are built right in.