4

I'm following the tutorial on setting up WURFL with Zend Framework to enable easy mobile browser detection.

http://framework.zend.com/manual/en/zend.http.user-agent.html#zend.http.user-agent.quick-start

I have got it setup to the point where it can detect a desktop browser and give me all the details and features of that browser, but when I try to access the website using an iPhone (mobile safari) it throws an error when trying to write to the cache directory.

Here's what I'm seeing in my error logs:

2011-06-08T22:32:34-07:00 ERR (3): The file cache directory does not exist and could not be created. Please make sure the cache directory is writeable: /var/tmp

However in my configuration at /application/configs/wurfl-config.php I have set the cache directory to the following:

<?php
$resourcesDir            = dirname(__FILE__) . '/../../data/wurfl/';

$wurfl['main-file']      = $resourcesDir  . 'wurfl-2.0.27.zip';
$wurfl['patches']        = array($resourcesDir . 'web_browsers_patch.xml');

$persistence['provider'] = 'file';
$persistence['dir']      = $resourcesDir . '/cache/';

$cache['provider']       = null;

$configuration['wurfl']       = $wurfl;
$configuration['persistence'] = $persistence;
$configuration['cache']       = $cache;

I've also ensured it is writable by the server, but wurfl seems to think my cache directory is still /var/tmp

How can I get wurfl to observe my cache directory setting?

Notes: The tutorial uses wurfl-1.1 as the example, I have only been able to find wurfl-1.3 on sourceforge. This may be an issue.

Notes: I have these lines in my application.ini file:

; WURFL
resources.useragent.wurflapi.wurfl_api_version = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/wurfl-php-1.3.0/WURFL/"
resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
AntBrown
  • 737
  • 2
  • 7
  • 11

6 Answers6

6

Not sure if this is the correct way to fix it, but for me the issue was solved by adding an extra .dir after the persistence.dir key (using WURFL 1.3.0):

In application.ini: (I don't use the php config file as I prefer not to mix in php code if I can use .ini directives)

resources.useragent.wurflapi.wurfl_config_array.persistence.dir.dir  = APPLICATION_PATH "/../data/wurfl/cache/"

So my complete config for WURFL looks like this in Zend's application.ini:

; Mobile device detection
resources.useragent.storage.adapter             = "Session"
resources.useragent.wurflapi.wurfl_api_version  = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir      = APPLICATION_PATH "/../library/WURFL/"
resources.useragent.wurflapi.wurfl_config_array.wurfl.main-file      = APPLICATION_PATH "/../data/wurfl/wurfl.xml"
resources.useragent.wurflapi.wurfl_config_array.wurfl.patches[]      = APPLICATION_PATH "/../data/wurfl/web_browsers_patch.xml"
resources.useragent.wurflapi.wurfl_config_array.persistence.provider = "file"
resources.useragent.wurflapi.wurfl_config_array.persistence.dir.dir  = APPLICATION_PATH "/../data/wurfl/cache/"

perhaps a bug in the framework regarding how it reads the config array it's being passed?

Jens Wegar
  • 4,147
  • 4
  • 29
  • 34
2

I just resolved the problem ;)

remove the [] from the code line below:

resources.useragent.wurflapi.wurfl_config_array.wurfl.patches[]      = APPLICATION_PATH "/../data/wurfl/web_browsers_patch.xml"

transform it to:

resources.useragent.wurflapi.wurfl_config_array.wurfl.patches = APPLICATION_PATH "/../data/wurfl/web_browsers_patch.xml"
sarnold
  • 102,305
  • 22
  • 181
  • 238
Rocco
  • 21
  • 1
  • Pity that your `patches[]` line isn't in your original question -- perhaps if the whole config file had been included, someone might have spotted your problem sooner. Also, [Jens](http://stackoverflow.com/questions/6299986/wurfl-with-zend-framework-ignoring-cache-directory-configuration/6423588#6423588) has a config with the `patches[]`, so further study would be worthwhile in any event. – sarnold Jun 22 '11 at 02:48
  • I never had a patches[] line in my original config, but after using Jens answer and this one I now have this part of it working. Thanks for everyones help. – AntBrown Jun 23 '11 at 02:09
2

It seems the format of the parameters has changed in version 1.3 - the WURFL docs here have the details and an example file.

So for the original question, the $persistence['dir'] line needs to be changed to:

$persistence['params']   = array(
    'dir' => $resourcesDir . '/cache/'
);
lamplightdev
  • 2,041
  • 1
  • 20
  • 24
  • Ah, that's where the docs are! Thank you for answering my initial question, as above I've gone with the .ini way of doing things but this answer is very helpful +1 from me! – AntBrown Jun 29 '11 at 04:56
2

I solved the problem using Wurfl 1.3.1 and reading this:

http://wurfl.sourceforge.net/nphp/

Giuseppe
  • 21
  • 1
1

With regards to Jens Wegar's answer above, there is a bug-fix request in to fix this as it's not clear.

http://framework.zend.com/issues/browse/ZF-12284

Community
  • 1
  • 1
HenryHayes
  • 368
  • 2
  • 4
  • 13
0

Did you configure the UserAgent resource to use the settings you are showing here?

You have to add resource.useragent.wurfl_* entries into your application.ini file.

Here is a sample:

resources.useragent.wurflapi.wurfl_api_version = "1.1"
resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/WURFL/"
resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
Carlo
  • 311
  • 2
  • 4
  • Yep, I've added these similar lines to the application.ini file: ; WURFL resources.useragent.wurflapi.wurfl_api_version = "1.1" resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/wurfl-php-1.3.0/WURFL/" resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php" – AntBrown Jun 14 '11 at 03:41