php develop tools super tools–zip web

 

1.What

    This super zip web tool is made by pkrss.com
    It is writed by php,need rewrite module,and can worked in apache and iis.

2.Introduction

    domain:http://api.pkrss.com (base dir is /demo/zipweb/)
    filelist:
            wwwroot\  
                    index.html
                    zip.php
                    zip\
                       a.zip
                       b.zip
                    .htaccess
    When your access http://api.pkrss.com/demo/zipweb/a/a1/a11.htm?param,
    1.this tool will pasre url,it known open a.zip,and read inner file name a1/a11.htm
    2.and read zip archive with filename zip/a.zip
    3.read inner file name a1/a11.htm
    4.output http header,and content
    x.if some error,will output 404.

3.function

1.support mime type with auto detect with apache mime_types file content

2.support zip http header detect,and zip compress content

3.support last_modify header detect,and intelligent return 301 http code.

4.source and demo

demo in here

source in here

zend framework 2 develop error log for phpcloud – 2 .htaccess

 

1.today i upload one application to zend 2 free php cloud.

after my previous fixed module name case sensitive problem. then i continute access the phpcloud website ,it output bellow message:

[Tue Mar 11 01:17:09 2014] [error] [client 172.17.255.254] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

 

and by my google search, i fixed it in public/.htaccess.

old .htaccess file content:

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

add RewriteBase / ,then .htaccess content like this:

RewriteEngine On
RewriteBase /
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

Last:

thanks!

zend framework 2 develop error log for phpcloud

1.today i upload one application to zend 2 free php cloud.

all is upload ok.and access the url,it is blank.and i see error in phpcloud –> application –> Overview –> Logs,in left function panel tree,i clicked error.and there is no error.

then i clicked php,it output bellow message:

[10-Mar-2014 01:53:08 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 01:53:25 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 01:54:39 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:04:57 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:05:08 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:07:08 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:07:16 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:07:20 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:40:58 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:41:00 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:42:08 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\InvalidArgumentException' with message 'Parameter to Zend\ModuleManager\ModuleManager's Zend\ModuleManager\ModuleManager::setModules method must be an array or implement the Traversable interface' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:235
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(63): Zend\ModuleManager\ModuleManager->setModules(NULL)
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/Mvc/Service/ModuleManagerFactory.php(120): Zend\ModuleManager\ModuleManager->__construct(NULL, Object(Zend\EventManager\EventManager))
#2 [internal function]: Zend\Mvc\Service\ModuleManagerFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'modulemanager', 'ModuleManager')
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ServiceManager/ServiceManager.php(853): call_user_func(Array, Object(Zend\S in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ServiceManager/ServiceManager.php on line 860
[10-Mar-2014 02:42:09 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\InvalidArgumentException' with message 'Parameter to Zend\ModuleManager\ModuleManager's Zend\ModuleManager\ModuleManager::setModules method must be an array or implement the Traversable interface' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:235
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(63): Zend\ModuleManager\ModuleManager->setModules(NULL)
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/Mvc/Service/ModuleManagerFactory.php(120): Zend\ModuleManager\ModuleManager->__construct(NULL, Object(Zend\EventManager\EventManager))
#2 [internal function]: Zend\Mvc\Service\ModuleManagerFactory->createService(Object(Zend\ServiceManager\ServiceManager), 'modulemanager', 'ModuleManager')
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ServiceManager/ServiceManager.php(853): call_user_func(Array, Object(Zend\S in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ServiceManager/ServiceManager.php on line 860
[10-Mar-2014 02:42:58 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:42:59 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:43:08 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:43:09 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:43:10 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:43:25 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:43:25 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:43:59 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:44:01 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:44:19 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:44:20 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:44:21 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:46:34 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 02:48:46 GMT] PHP Fatal error:  Undefined class constant 'init' in /home/pkimage/.apps/http/__default__/0/1.0-zdc/public/index.php on line 10
[10-Mar-2014 02:49:06 GMT] PHP Fatal error:  Undefined class constant 'init' in /home/pkimage/.apps/http/__default__/0/1.0-zdc/public/index.php on line 11
[10-Mar-2014 02:49:49 GMT] PHP Fatal error:  Undefined constant 'Zend\Mvc\Application' in /home/pkimage/.apps/http/__default__/0/1.0-zdc/public/index.php on line 11
[10-Mar-2014 02:49:50 GMT] PHP Fatal error:  Undefined constant 'Zend\Mvc\Application' in /home/pkimage/.apps/http/__default__/0/1.0-zdc/public/index.php on line 11
[10-Mar-2014 03:18:11 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on line 175
[10-Mar-2014 11:59:40 GMT] PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175
Stack trace:
#0 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('local')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerLi in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php on l

 

look,there is

 PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (local) could not be initialized.' in /usr/local/zend/var/libraries/Zend_Framework_2/2.2.2/library/Zend/ModuleManager/ModuleManager.php:175

ok. in project/config/application.config.php:

// ... other code
return array(
    // This should be an array of module namespaces used in the application.
    'modules' => array(
        'Application','Api','local',
    ),
// ... other code

oh,The module is Local,not local. my develop machine is windows iis, so may be pass no error present.but phpcloud is linux apache.so may be case insense.

return array(
    // This should be an array of module namespaces used in the application.
    'modules' => array(
        'Application','Api','Local',
    ),

fixed!

Last:

thanks!

zend framework 2 develop log 4 – multi language i18n translate

1.plan

1.1 why write this blog

because i want to share my experience  for your.

1.2 what purpose

my zend framework 2 index will detect user browser language,and intelligent redirect to other uri ex: xxx/controller/action/uilang/data locale id/other params.

2. do

2.1 designer draft

a. the detect user browser is implement in project/Application/view/application/index/index.phtml view file.it will used user browser header value $uilang = $_SERVER["HTTP_ACCEPT_LANGUAGE"].then give my mysql locale table,select localeid from localetable where locale=$uilang.and redirect to default target url.

b.default target url page will parse uilang and localeid param,when process data or redirect other uri,can used these value.

c.look up zend framework 2 route mechanism,and finished these step.

2.2 code

project/module/Application/src/Application/Controller/IndexController.php file source:

<?php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        return new ViewModel(array('controller' => $this));
    }
}

project/module/Application/view/application/index/index.phtml view file source:

<?php 

$localeTable = $this->controller->getServiceLocator()->get('Api\Model\LocaleTable');
$locales = $localeTable->getLocales();

$uilang = \Application\View\Helper\LocaleHelper::getUserBrowserLocale();

$lid = \Application\View\Helper\LocaleHelper::getLidFromLocale($locales,$uilang);

$this->controller->plugin('redirect')->toRoute('application/rank',array('uilang' => $uilang, 'lid' => $lid));

?>

project/module/Application/src/Application/View/Helper/LocaleHelper.php file source:

<?php
/**
 * Application\View\Helper
 * 
 * @author liandeliang@gmail.com
 * @version 1.0.0
 */
namespace Application\View\Helper;

use Zend\View\Helper\AbstractHelper;

/**
 * View Helper
 */
class LocaleHelper extends AbstractHelper
{

    public function __invoke($in)
    {
        // TODO Auto-generated UtilsHelper::__invoke
        return $in;
    }
    
    private static function _getLocaleInfo($locale,$locales){
        foreach($locales as &$item){
            if($item['locale'] === $locale)
                return $item;
        }
        return null;
    }
    
    public static function getLidFromLocale($locales,$locale){
        $lid = 1;
        do{
            if(!$locales || !count($locales) || empty($locale))
                break;
            
            // direct query
            $info = self::_getLocaleInfo($locale,$locales);
            if($info){
                $lid = $info['id'];
                break;
            }
            
            // to lower query
            $locale = strtolower($locale);
            foreach($locales as &$item)
                $item[locale] = strtolower($item[locale]);
            
            $info = self::_getLocaleInfo($locale,$locales);
            if($info){
                $lid = $info['id'];
                break;
            }
            
            // replace character query
            $locale = strtok($locale,'_');
            foreach($locales as &$item)
                $item[locale] = strtok($item[locale],'_');
            
            $info = self::_getLocaleInfo($locale,$locales);
            if($info){
                $lid = $info['id'];
                break;
            }
            
            // get first lid
            $info = $locales[0];
            $lid = $info['id'];
            
        }while(false);
        
        return $lid;
    }
    
    public static function getUserBrowserLocale(){
        $ret = 'en_US';
        do{
            if(!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
                break;
            
            // This means that you do not have the intl extension running. Locate your php.ini for 'intl' and enable it or contact your host (if youre on any hoster) 
            // return \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
            
            $langs = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
            if(empty($langs))
                break;
            
            $langs = explode(';', $langs);
            if(!langs || !count($langs))
                break;
            
            $langs = explode(',', $langs[0]);
            if(!langs || !count($langs))
                break;
            
            $ret = $langs[0];
            $ret = str_replace('-', '_', $ret);
        }while(false);
        
        return $ret;
    }
    
    public static function setTranslateLocale($controller){
        do{
            $translator = $controller->getServiceLocator()->get('translator');
            if(!$translator)
                break;
            
            $uilang = $controller->params('uilang');
            if(empty($uilang))
                $uilang = self::getUserBrowserLocale();
            
            if(!empty($uilang)){
                $translator->setLocale($uilang);
                $translator->setFallbackLocale('en_US');
            }
        }while(false);
    }
}

project/module/Application/config/module.config.php file source:

<?php

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'rank' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/rank[/:action[/:uilang[/:lid]]]',
                            'constraints' => array(
                                'action'     => '[a-zA-Z0-9_-]*',
                                'lid' => '\d*',
                                'uilang' => '[a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                                'controller' => 'Rank',
                                'action'     => 'internet',
                                'uilang'     => 'en',
                                'lid'        => 1,
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    // ... other code
);

xxx/Model/Locale.php file source code:

<?php
namespace Api\Model;

class Locale
{
    public $id;
    public $locale;
    public $country;

    public function exchangeArray($data)
    {
        $this->id     = (isset($data['id'])) ? $data['id'] : null;
        $this->locale = (isset($data['locale'])) ? $data['locale'] : null;
        $this->country  = (isset($data['country'])) ? $data['country'] : null;
    }
    
    public function toArray(){
        $ret = array();
        $ret['id'] = $this->id;
        $ret['locale'] = $this->locale;
        $ret['country'] = $this->country;
        return $ret;
    }
}

xxx/Model/LocaleTable.php file source code:

<?php
namespace Api\Model;

use Zend\Db\TableGateway\TableGateway;

/*
CREATE TABLE `locale` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `locale` char(5) NOT NULL,
 `country` varchar(128) NOT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `locale` (`locale`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 */
class LocaleTable
{
    protected $tableGateway;

    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    public function fetchAll()
    {
        $resultSet = $this->tableGateway->select();
        return $resultSet;
    }

    public function getLocales()
    {        
        $rowset = $this->tableGateway->select();
        
        $ret = array();
        foreach ($rowset as $row) {
            $ret []= $row->toArray();
        }
        
        return $ret;
    }

    public function getLocale($id)
    {
        $id = (int)$id;
        
        if(!$this->tableGateway->isInitialized())
            $this->tableGateway->initialize();
        
        $rowset = $this->tableGateway->select(array('id' => $id));
        $ret = $rowset->current();
        if($$ret)
          $ret = $ret->toArray();
        
        return $ret;
    }

    public function saveLocale(Locale $locale)
    {
        $data = array(
                'id' => $locale->id,
                'locale' => $locale->locale,
                'country' => $locale->country,
        );

        $id = (int)$locale->id;
        if ($id == 0) {
            $this->tableGateway->insert($data);
        } else {
            if ($this->getLocale($id)) {
                $this->tableGateway->update($data, array('id' => $id));
            } else {
                throw new \Exception('Locale id does not exist');
            }
        }
    }

    public function deleteKeyword($id)
    {
        $this->tableGateway->delete(array('id' => $id));
    }
}

mysql locale data table and data:


CREATE TABLE IF NOT EXISTS `locale` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `locale` char(5) NOT NULL,
  `country` varchar(128) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `locale` (`locale`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=47 ;


INSERT INTO `locale` (`id`, `locale`, `country`) VALUES
(1, 'en', 'English'),
(2, 'zh_CN', '简体中文'),
(3, 'af', 'Afrikaans'),
(4, 'bg', 'Bulgarian'),
(5, 'ca', 'Catalonian'),
(6, 'cs', 'Czech'),
(7, 'da', 'Danish'),
(8, 'de', 'German'),
(9, 'el_GR', 'ελληνικά'),
(10, 'en_GB', 'English (UK)'),
(11, 'es', 'Spanish/Latin American'),
(12, 'fa', 'فارسی (فارسی)'),
(13, 'fi', 'Finnish'),
(14, 'fr_CA', 'France (Canadian)'),
(15, 'fr', 'France (France)'),
(16, 'gr', 'Ελληνικά (παλαιά έκδοση)'),
(17, 'he', 'Hebrew'),
(18, 'hr', 'hrvatski'),
(19, 'hu', 'Hungarian'),
(20, 'id', 'Indonesian'),
(21, 'it', 'Italian'),
(22, 'ja', '日本'),
(23, 'ko', '한국의'),
(24, 'lt', 'Lithuanian'),
(25, 'lv', 'Latvian'),
(26, 'mk', 'Македонија'),
(27, 'nl', 'Dutch'),
(28, 'no_NB', 'Norwegian Bokm?l'),
(29, 'no_NN', 'Norwegian Nynorsk'),
(30, 'pl', 'Polish'),
(31, 'pt_BR', 'Portuguese/Brazil'),
(32, 'pt_PT', 'Portuguese/Portugal'),
(33, 'ro', 'Romanian'),
(34, 'ru', 'Россия'),
(35, 'sk', 'Slovak'),
(36, 'sl', 'Slovenian'),
(37, 'sr_RS', 'Српски Ћирилица'),
(38, 'sr', 'Serbiae Latine'),
(39, 'sv_SE', 'Swedish'),
(40, 'th', 'Thailand'),
(41, 'tr', 'Turkish'),
(42, 'ukr', 'Український'),
(43, 'vn', 'Việt'),
(44, 'zh_TW', '中華臺灣'),
(45, 'zh_HK', '中國香港'),
(46, 'reser', 'Reserve');

3.check

when i access default uri:http:// localhost/projectname/

then it redirect to http:// localhost/projectname/rank/internet/zh_CN/2

next timer,when i want to redirect to other url in rank/index view,then get $uilang = $this->controller->params(‘uilang’,’en_US’) and $lid = $this->controller->params(‘lid,1); ,and get new other target uri by code:

$this->controller->plugin('url')->fromRoute('application/image',array('q' => $item['key'],'uilang' => $uilang))

4.action

interflow with me,wait for improve,

5.last

thanks!

zend2 framework develop log 3– redirect router or url

 

1. what

i want to redirect url in zend framework 2,and after my search,i found bellow method:

way 1

return $this->redirect()->toUrl('YOUR_URL');

way 2

return $this->redirect()->toRoute('ModuleName',
  array('controller'=>$controllerName,
        'action' => $actionName,
        'params' =>$params));

way 3

return $this->redirect()->toRoute('dns-search', array(
    'companyid' => $this->params()->fromRoute('companyid')
));

Where dns-search is the route I want to redirect to and companyid are the url params.

In the end the URL becomes /dns/search/1 (for example)

way 4

header( "Location: " . "other url" );
exit();

2. error

i get bellow error message:

An error occurred

An error occurred during execution; please try again later.

Additional information:

Zend\ServiceManager\Exception\ServiceNotFoundException

File:
D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\ServiceManager\ServiceManager.php:495
Message:
Zend\View\HelperPluginManager::get was unable to fetch or create an instance for redirect
Stack trace:
#0 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\ServiceManager\AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('redirect', true)
#1 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\View\Renderer\PhpRenderer.php(378): Zend\ServiceManager\AbstractPluginManager->get('redirect', NULL)
#2 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\View\Renderer\PhpRenderer.php(397): Zend\View\Renderer\PhpRenderer->plugin('redirect')
#3 D:\doc\webserver\php\book\module\Application\view\application\rank\index.phtml(45): Zend\View\Renderer\PhpRenderer->__call('redirect', Array)
#4 D:\doc\webserver\php\book\module\Application\view\application\rank\index.phtml(45): Zend\View\Renderer\PhpRenderer->redirect()
#5 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\View\Renderer\PhpRenderer.php(507): include('D:\doc\webserve...')
#6 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#7 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\View\View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#8 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\View\View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#9 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#10 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#11 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#12 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
#13 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\Mvc\Application.php(347): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))
#14 D:\work\zend2\.metadata\.plugins\org.zend.php.framework\org.zend.php.framework.v2.CONTAINER\Zend\Mvc\Application.php(322): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#15 D:\doc\webserver\php\book\public\index.php(12): Zend\Mvc\Application->run()
#16 {main}

why:

because  $this->plugin(‘redirect’) is AbstractActionController member function,not in view.

if i call view with redirect plugin parameter in controller liked this:

public function indexAction()
    {
        return new ViewModel(array('sm' => $this->getServiceLocator(),'redirect' => $this->plugin('redirect')));
    }

then in index.phtml view used this plugin it like this:

<a href="' . $this->redirect->toRoute('application',array(
                            'controller' => 'rank',
                            'action' => 'index',
                            'params' => array(),
                        )) . '" class="divWorkStatistTableColWord">' . $item['key'] . '</a>

then after access this url,it will auto redirect to target url.

but i only want to get target url string,not auto redirect to it.

and more official description is here.

fixed:

See source in Zend\Mvc\Controller\Plugin\Redirect.php.

then get target url in internet.phtml view, can done by bellow code:

<a href="' . $this->controller->plugin('url')->fromRoute('application/image',array('q' => $item['key'])) . '" class="divWorkStatistTableColWord">' . $item['key'] . '</a>

and $this->controller variable is set in parent RankController.php:

public function internetAction()
    {
        return new ViewModel(array('controller' => $this));
    }

and the route name ‘application/image’ is set in parent config/module.config.php:

<?php

// @see http://framework.zend.com/manual/2.1/en/modules/zend.mvc.routing.html
return array(
    'router' => array(
        'routes' => array(
            // ...
            
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'rank' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/rank[/:action[/:lid]]',
                            'constraints' => array(
                                'action'     => '[a-zA-Z0-9_-]*',
                                'lid' => '\d*',
                            ),
                            'defaults' => array(
                                'controller' => 'Rank',
                                'action'     => 'internet',
                                'lid'        => 1,
                            ),
                        ),
                    ),
                    'image' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/image[/:action[/:q]]',
                            'constraints' => array(
                                'action'    => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'q'         => '.*',
                            ),
                            'defaults' => array(
                                'controller' => 'Image',
                                'action'   => 'book',
                                'q'        => 'hello',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
// ...
);

above ImageController.php code,is no need paste here.

Last:

Thanks!

zend2 framework develop log 2– render many partial layout

1.introduction

i want to dynamic use js and css file in layout.layout.

My origin method is design(bellow way-2,but way-1 is easy and useful):

there are two layout files:

Application\view\layout\:

                                        layout.layout

                                        rank.layout

and my view want to render rank.layout,and rank.layout will partial layout.layout.

3.code

3.1 way 1 – view –> call layout

module/Application/view/application/rank/index.phtml:

<?php 

$baseResPath = $this->basePath();
$this->headLink()
    ->appendStylesheet($baseResPath . '/css/book/SearchRank.css')
    ->appendStylesheet($baseResPath . '/css/book/BookShelf.css');

if(defined('PK_DEBUG_MODE')){
    $this->inlineScript()->appendFile($baseResPath . '/js/third/jquery/jquery-old.js', 'text/javascript');            
}else{
    $this->inlineScript()->appendFile('http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js', 'text/javascript');
} 

?>

module/Application/view/layout/layout.phtml:

<?php echo $this->doctype(); ?>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <?php echo $this->headTitle('pkrss '. $this->translate('images book'))->setSeparator(' - ')->setAutoEscape(false);
              echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0');
              
              
              echo $this->headLink(array('rel' => 'shortcut icon', 'href' => $this->basePath() . 'favicon.ico'));
        ?>
    </head>
    <body>
        <?php echo $this->content;
        
        echo $this->inlineScript();
        ?>
    </body>
</html>

result then output source for xxx/application/rank/index:

<!DOCTYPE html><html lang="en">
    <head>
        <meta charset="utf-8">
        <title>pkrss images book</title><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="/book/public/css/book/SearchRank.css" media="screen" rel="stylesheet" type="text/css">
<link href="/book/public/css/book/BookShelf.css" media="screen" rel="stylesheet" type="text/css">
<link href="/book/publicfavicon.ico" rel="shortcut icon">    </head>
    <body>
        <script type="text/javascript" src="/book/public/js/third/jquery/jquery-old.js"></script>    </body>
</html>

 

3.2 way 2 – use layout call layout

switch show rank.layout

module/Application/src/Application/Controller/RankController.php:

<?php
namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class RankController extends AbstractActionController
{
    public function indexAction()
    {
        $this->layout('layout/rank');
        return new ViewModel();
    }
}

module/Application/view/layout/layout.phtml:

<?php echo $this->doctype(); ?>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <?php echo $this->headTitle('pkrss '. $this->translate('images book'))->setSeparator(' - ')->setAutoEscape(false);
              echo $this->headMeta()->appendName('viewport', 'width=device-width, initial-scale=1.0');
              
              echo $this->headLink(array('rel' => 'shortcut icon', 'href' => $this->basePath() . 'favicon.ico'));
        // echo $this->headScript()->prependFile($this->basePath() . '/js/jquery-old.js', 'text/javascript')
        ?>
    </head>
    <body>
        <?php echo $this->content;
        
        echo $this->inlineScript();
        ?>
    </body>
</html>

module/Application/view/layout/rank.phtml:

<?php 

$baseResPath = $this->basePath();  // '/s/ful/';
$this->headLink()
    ->appendStylesheet($baseResPath . '/third/bookreader/BookReader/BookReader.css')
    ->appendStylesheet($baseResPath . '/css/book/BookReader.css')
    ->appendStylesheet($baseResPath . '/css/book/BookShelf.css');

if(defined('PK_DEBUG_MODE')){
    $this->inlineScript()->appendFile($baseResPath . '/js/third/jquery/jquery-old.js', 'text/javascript')
        ->appendFile($baseResPath . '/js/third/jquery-ui/jquery-ui.js')
        ->appendFile($baseResPath . '/js/third/dragscrollable/dragscrollable.js')
        ->appendFile($baseResPath . '/js/third/jquery-colorbox/jquery.colorbox.js')
        ->appendFile($baseResPath . '/js/third/jquery-ui/jquery.ui.ipad.js')
        ->appendFile($baseResPath . '/js/third/jquery-bt/jquery.bt.js')
        ->appendFile($baseResPath . '/js/book/BookReader.js')
        ->appendFile($baseResPath . '/js/book/utils.js')
        ->appendFile($baseResPath . '/js/native/core.js')
        ->appendFile($baseResPath . '/js/utils/db.js')
        ->appendFile($baseResPath . '/js/book/pkBookShelf.js')
        ->appendFile($baseResPath . '/js/book/pkBookImage.js')
        ->appendFile($baseResPath . '/js/book/main.js')
        ->appendFile($baseResPath . '/js/book/BookReaderJSSimple.js')
        ->appendFile($baseResPath . '/js/plugin/book_photomenu.js')
        ->appendFile($baseResPath . '/js/plugin/o_flickr.js')
        ->appendFile($baseResPath . '/js/plugin/o_bing.js')
        ->appendFile($baseResPath . '/js/plugin/book_localphoto.js')
        ->appendFile($baseResPath . '/js/plugin/o_authhtm.js');
}else{
    $this->inlineScript()->appendFile('http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js', 'text/javascript')
        ->appendFile('http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.4/jquery-ui.min.js')
        ->appendFile($baseResPath . '/js/book-all.js');
}

    echo $this->partial('layout/layout',array('content' => $this->content));
?>

module/Application/config/module.config.php:

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            // The following is a route to simplify getting started creating
            // new controllers and actions without needing to create a new
            // module. Simply drop new controllers in, and you can access them
            // using the path /application/:controller/:action
            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
        ),
    ),
    'translator' => array(
        'locale' => 'en_US',
        'translation_file_patterns' => array(
            array(
                'type'     => 'gettext',
                'base_dir' => __DIR__ . '/../language',
                'pattern'  => '%s.mo',
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController',
            'Application\Controller\Rank' => 'Application\Controller\RankController',
        ),
    ),
    'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => true,
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'layout/rank'           => __DIR__ . '/../view/layout/rank.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
'view_helpers' => array(
'invokables' => array(
    'OutputHelper' => 'book\module\Application\OutputHelper',
        ),
    )
);

result then output source for xxx/application/rank/index:

<!DOCTYPE html><html lang="en">
    <head>
        <meta charset="utf-8">
        <title>pkrss images book</title><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="/book/public/third/bookreader/BookReader/BookReader.css" media="screen" rel="stylesheet" type="text/css">
<link href="/book/public/css/book/BookReader.css" media="screen" rel="stylesheet" type="text/css">
<link href="/book/public/css/book/BookShelf.css" media="screen" rel="stylesheet" type="text/css">
<link href="/book/publicfavicon.ico" rel="shortcut icon">    </head>
    <body>
        <script type="text/javascript" src="/book/public/js/third/jquery/jquery-old.js"></script>
<script type="text/javascript" src="/book/public/js/third/jquery-ui/jquery-ui.js"></script>
<script type="text/javascript" src="/book/public/js/third/dragscrollable/dragscrollable.js"></script>
<script type="text/javascript" src="/book/public/js/third/jquery-colorbox/jquery.colorbox.js"></script>
<script type="text/javascript" src="/book/public/js/third/jquery-ui/jquery.ui.ipad.js"></script>
<script type="text/javascript" src="/book/public/js/third/jquery-bt/jquery.bt.js"></script>
<script type="text/javascript" src="/book/public/js/book/BookReader.js"></script>
<script type="text/javascript" src="/book/public/js/book/utils.js"></script>
<script type="text/javascript" src="/book/public/js/native/core.js"></script>
<script type="text/javascript" src="/book/public/js/utils/db.js"></script>
<script type="text/javascript" src="/book/public/js/book/pkBookShelf.js"></script>
<script type="text/javascript" src="/book/public/js/book/pkBookImage.js"></script>
<script type="text/javascript" src="/book/public/js/book/main.js"></script>
<script type="text/javascript" src="/book/public/js/book/BookReaderJSSimple.js"></script>
<script type="text/javascript" src="/book/public/js/plugin/book_photomenu.js"></script>
<script type="text/javascript" src="/book/public/js/plugin/o_flickr.js"></script>
<script type="text/javascript" src="/book/public/js/plugin/o_bing.js"></script>
<script type="text/javascript" src="/book/public/js/plugin/book_localphoto.js"></script>
<script type="text/javascript" src="/book/public/js/plugin/o_authhtm.js"></script>    </body>
</html>

4.Last

Thanks !

Global can earn money wordpress blog Advertising Alliance Introduction–3 infolinks

1.what is Infolinks

Infolinks leads the online advertising industry by driving new revenue opportunities for publishers while overcoming banner blindness for advertisers.

Infolinks drives new revenue for publishers by delivering intent-based ads in non-traditional web places. Select from a range of elegant and innovative ad units that best suit your needs, fully customize their appearance and easily add them to your site with our 1-minute integration plugins.
Infolinks ad units include:

Capitalize on browser margins with attractive display ads.
Engage users with an overlay ad unit most relevant to the user's intent.
Display a tag cloud of keywords relevant to your content.
Monetize inside the lines by highlighting your best keywords.

Advertiser Solutions
Infolinks empowers advertisers to reach consumers with highly targeted, intent-based ad units. Our ads appear in non-traditional, yet effective placements to increase engagement and overcome banner blindness. Why burn your budget on ads that consumers nearly universally ignore when Infolinks delivers 30x the engagement of standard ads? Create your own campaign in minutes using our simple Self-Serve Marketplace, or contact an account manager to help you get started.

Advertise with Intent
Target consumers based on intent, to achieve a higher response rate.

Powerful Engagement
Serve ads only to hand-raisers – people who are truly interested.

Make the Most of Your Ads
Budget efficiently with competitive pricing and real-time bidding.

Global Reach
Join the platform delivering billions of monthly impressions across 100,000+ sites in 128 countries.

Office web

2.Screen shots

2.1 my blog screenshots

In my blog, http://blog.pkrss.com it will show like this:

image

3.Register and login

After your register,it need 1 work day to audit,and can easy passed.

4.dashboard

after your register and login,in dashboard control panel.it has some navigate menus: Repoerts, Integrate, Customize, Account, New, FAQ, BLOG.

4.1 Add website

with menus Account –> MyWebsites,

in left panel,there is one message:

According to the Infolinks terms and conditions, payments are processed up to 45 days after the end of each billing cycle.

We here at Infolinks work hard to insure our customers receive their payments as soon as possible, but there are many external factors such as country of residence and payment method that effect the payment process.

As always we are here to answer any questions you might have.

Thank you,
The Infolinks Team.

and i ignore it,clicked “Add website”:

Add Website
To add additional websites to your account, simply fill in your website's details below and click "submit".
-------------------------------------------
Website URL:*Website category:
Select:  *Website language:
Select... 
Comments:
-------------------------------------------
* Denotes required fields.

i type my website url:”blog.pkrss.com”

Websites category:”Internet & telecom”

Website language:”english”

Comments: “blog of my website”.

then clicked “Submit”.

after that,it’s Status is pending.and will be audit in work days.

4.2 Integrade

i clicked “wordpress” button,and operator bellow it’s instructions,to setup infolinks wordpress plugin for my blog websites.

4.3 wordpress plugins profile:

it’s default plugin setting is good.

and if your can custom by your wordpress admin page, after your install and active above wordpress plugin, “Setting” –> “Infolinks setting”,and it will show:

Infolinks Official Plugin
This plugin will automatically add your Infolinks script to your website pages
 
Infolinks In Text Ads:     On /  Off (On)
 
Publisher ID : Please enter your infolinks pid (my is 2045859)
Website ID : Please enter your website wsid (my is 0)
 
Exclude from the following pages  (please enter page numbers comma- separated. Infolinks will not be added to these pages)
 
jQuery :     Use plugin jQuery / Use site jQuery (Use plugin jQuery)
 
Show in header / titles: 
(jQuery is mandatory for this feature)    On / Off (On)
 
 Enable Infolinks on posts / Enable Infolinks on comments (selected two options)
 
Want to earn even more?
Click here to activate Tag Cloud on your pages

By adding Tag Cloud to your pages, you can increase your earnings with our attractive, fully-customizable cloud of keywords that display in a Tag Cloud unit at the bottom of your text.

Tag Cloud operates just like our In-Text ads, a mouse hover reveals our ad bubble, and each click equals more money for you! Our smart algorithm delivers the best keywords for each page and helps to further turn your content into money by matching each keyword with a relevant ad.

 
To view or edit your Infolinks account settings, please visit the Integration guide 
and our FAQs, or contact us at support@infolinks.com

image

and clicked “Save setting”.

5.result

your can see this effect in my blog.

Global can earn money wordpress blog Advertising Alliance Introduction–2 Chitika

1.what is Chitika

Develops real-time, scalable, on-demand contextual targeting services to help online businesses leverage their two biggest assets: content and online

We collect information about your activities on certain websites to send you targeted advertisements. To opt out of Chitika’s targeted ads.

Office web

2 screenshots

image

3.Register and login

image

clicked “SIGN UP”,to register.

image

type your emain,and clicked “GET STARTED”.

then it will popup one screen,and show bellow message:

Fast. Easy. Free.
You’re 30 seconds away from
making more money with Chitika.

One More Thing:
We need you to verify your email address by clicking the link in the email we sent.

Add support@chitika.com to your address book to ensure delivery.

Please contact Chitika Support if you do not receive a confirmation email within one hour.

goto your email,to active that.in email,that message will show like this:

 Welcome to Chitika! To get started using your Chitika Account, please confirm your email address by clicking the button below:
Verify Your Email Address
Chitika, Inc.

1800 West Park Drive

Suite 300

Westborough, MA 01581

clicked “Verify your email Address”.

then will open one url,and show liked this:

You're Almost Done!
First Name

Last Name

Password

Confirm Password

Country

Website URL

Client Name

Name of your Website or Business

after your type then,clicked “COMPLETE APPLICATION”.

4. GET CODE

then it will redirect one new page,and show bellow message:

Welcome to Chitika!
Hi lian,
We're excited you've chosen us to help drive your online revenue, and we're going to do all we can to help you succeed! Trust in our smart ad technology that will determine the best ad type(s) to show on your site in order to make you the most money possible. This could include a combination of text, display, or rich media ad units. For more information, contact Chitika Support.


Get Your Code
Below, we've generated some unique ad code for our best-performing ad unit, the 550x250 size. We suggest you place this ad between blog posts or within content to help it perform at its peak. Simply click within the box to copy your personalized code, paste it to your site, and relax -- our ads will work for you! 
<script type='text/javascript'>
    ( function() {
    if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] } };
    var unit = {
        'publisher' : 'pkrss',
        'width' : 300,
        'height' : 250,
        'sid' : 'Chitika Default'
    };
    var placement_id = window.CHITIKA.units.length;
    window.CHITIKA.units.push(unit);
    document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.src = 'http://scripts.chitika.net/getads.js';
    try {
        document.getElementsByTagName('head')[0].appendChild(s);
    } catch(e) {
        document.write(s.outerHTML);
    }
    }());
</script>

then clicked “GO TO YOUR DASHBOARD”.

5.dashboard

5.1 screenshots

image

5.2 ui description

left  panel is “recommended”

center panel is custom get code.

right panel is other links.

5.3 center panel custom get code

top is:

Quick Start Guidelines
To earn money with Chitika, start by generating your custom code. We recommend the 550x250 ad unit, our best performing ad size! Change the colors to match your site, add an alternate URL, or simply grab one of our other recommended ad sizes to the left. You can also check out our expert tips on the right to learn more about the best places for your ads. Questions? Email support@chitika.com -- we’re here to help!

i selected “Ad Code Generator” => “Format”: 250*250 Square

and that example will show:

Your ads may be slightly different based on your customization options and website content

5.3.1 custom

i clicked “custom”,and it have 3 tab: “Options”,“Colors”,“Reporting”.

it looks like have no custom for me.so i clicked “get code”.

5.3.2 get code

after i clicked “get code”.it will popup one window like this:

Click here for help on adding code to your site

<script type="text/javascript">
  ( function() {
    if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] }; };
    var unit = {"publisher":"pkrss","width":250,"height":250,"sid":"Chitika Default"};
    var placement_id = window.CHITIKA.units.length;
    window.CHITIKA.units.push(unit);
    document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.src = '//cdn.chitika.net/getads.js';
    try { document.getElementsByTagName('head')[0].appendChild(s); } catch(e) { document.write(s.outerHTML); }
}());
</script>

Paste this code where you want the ad to appear on your website.

then clicked “close”.

install chitika plugin in wordpress.

 

Global can earn money wordpress blog Advertising Alliance Introduction–1 BidVertiser

1.what is bidvertiser

Pay per click advertising – online advertising directly on sites of your choice, internet marketing solution for online advertisers. Webmasters make money online.

it can earn money for your wordpress blog.

Office Web

2.Screen shots

2.1 my blog screenshots

In my blog, http://blog.pkrss.com it will show like this:

image

3.Register and login

After your register,it no need audit,and can easy passed.

4.add websites

4.1 “MANAGE BIDVERTISERS” => “Add new BidVertise”:

image

4.2 checked “Add new BidVertiser under a new domain”

Use this option only if you would like to run the BidVertiser ads on another domain name.

Please fill in the information of the website you would like to place the BidVertiser ads on. After filling out the form, click “Finish”.

4.3 BidVertiser Title:

Unique identifier to help you better manage your BidVertisers, for example, “index page”, or “about us”

i typed “blog.pkrss.com”

4.4 URL of your website:

Only enter the main URL of your website, as you will be able to place ads on every page under this URL
(e.g. on any page under http://www.your-site.com/…..)

i typed “http://blog.pkrss.com

not checked “3rd party ad server / URL forwarding: (optional)”

Check this box only if your ads are served from a different domain,
such as 3rd party ad server or URL forwarding that serves your website/blog in a frame with a different domain.

4.5 Primary language of your website:

i selected “english”

4.6 Select a category that most accurately describes your website:

Select main category

i selected “Computer and internet”

4.7 Select sub category

i selected “Web master and blog resource”

4.8 note:

Please be as accurate as possible, as the above information will be reviewed by our editorial team. Choosing the wrong language or category may lead to URL rejection.

4.9 clicked “finished”.

5.choose template

in “MANAGE BIDVERTISERS” => “BidVertiser Center”:

5.1 screenshots

image

5.2 selected your want to used for websites

i selected “http://blog.pkrss.com”

5.3 clicked “choose template”

then popup one window ,and  screenshots:

image

it haved:

bannels: Full Banner (468×60) Leaderboard (728×90)

skyscrapers:Wide Skyscraper (160×600) Skyscraper (120×600)

rectangles:Medium Rectangle (300×250) Large Rectangle (336×280)

mobile: Mobile Banner (300×50)

5.4 selected your want choose

5.5 clicked update

image

6. preferences

6.1 click “preferences”

image

6.2 it will popup one options window:

screenshots:

image

Change preferences for the ads displayed on http://blog.pkrss.com:

BidVertiser Title:    
Unique identifier to help you better manage your BidVertisers, for example, "index page", or "about us"
 (optional) 3rd party ad server / URL forwarding:

Check this box only if your ads are served from a different domain, such as 3rd party ad server or URL forwarding that serves your website/blog in a frame with a different domain.
Display eBay Ads    
    Yes               No
(Choose "No" to have only text ads running. eBay Ads are live eBay auctions ads. See example.)
(Choose "No" to have only text ads running. Image Ads are standard graphical ads)
Display Pop-Under Ads    
    Yes               No
(Choose "No" to disable Pop-Under Ads. Please remember that Pop-Under Ads will result in much higher conversion bonuses in your monthly payment!)
Display Slider Ads    
    Yes               No
(Choose "No" to disable Slider Ads. Allowing Slider Ads will result in higher revenues and we recommend having them enabled!)
Primary language of your website :    English
Category: Computer & Internet --> Webmasters & Blogging Resources
* Your website category has been assigned and locked by our editorial team. If you feel that there is another category that better match your website, please contact us.

7 get advertisement code

7.1 clicked “get ad code”:

image

7.2 it will be popup one window:

image

Get the Ad Code for http://blog.pkrss.com:

Below you can find your personalized BidVertiser HTML code. Simply Copy (CTRL+C) and Paste (CTRL+V) it into the BODY of your HTML pages.
This code is specific for http://blog.pkrss.com and for any inner pages under it. Placing it on different domain will result in clicks that will not be counted as valid.
(If you wish to run BidVertiser ads on another domain, simply click on "Add new BidVertiser" on the menu.)
Try to place the code above the scroll, near the top of your web pages, which can be viewed without scrolling. This will dramatically increase your click ratio, thus, your earnings.

Note: you will only need to paste this code once. Any future changes you will apply to the layout of the ads, like colors and fonts, will be updated automatically on your website.
Please note:
If you have just created this ad spot, please make sure to refresh the web pages where the code is placed on a few times to allow our ad servers to fully utilize.

8.result code

put your ad code to your web blogs.

 <!-- Begin BidVertiser code -->
<SCRIPT LANGUAGE="JavaScript1.1" SRC="http://bdv.bidvertiser.com/BidVertiser.dbm?pid=592473&bid=1479442" type="text/javascript"></SCRIPT>
<noscript><a href="http://www.bidvertiser.com">make money online</a></noscript>
<!-- End BidVertiser code --> 

zend2 framework develop log 1– mysql and mvc and view helper and json response

Introduction:

This blog is about zend 2 framework,and not good. because is have so hard to read.

Contain:

  • mysql profile.
  • mvc
  • no view render
  • json output
  • gzip compress
  • view helper

 

1.db profile (mysql)

1.1 db profile

1.1.1 config/autoload/local.php

(description:this is local private profile file.)

<?php
/**
 * Local Configuration Override
 *
 * This configuration override file is for overriding environment-specific and
 * security-sensitive configuration information. Copy this file without the
 * .dist extension at the end and populate values as needed.
 *
 * @NOTE: This file is ignored from Git by default with the .gitignore included
 * in ZendSkeletonApplication. This is a good practice, as it prevents sensitive
 * credentials from accidentally being committed into version control.
 */

define('PK_DEBUG_MODE',true);

return array(
    // Whether or not to enable a configuration cache.
    // If enabled, the merged configuration will be cached and used in
    // subsequent requests.
    //'config_cache_enabled' => false,
    // The key used to create the configuration cache file name.
    //'config_cache_key' => 'module_config_cache',
    // The path in which to cache merged configuration.
    //'cache_dir' =>  './data/cache',
    // ...
    'db' => array(
            'driver'         => 'Pdo',
            'username' => 'root',
            'password' => '',
            'dsn'            => 'mysql:dbname=db1;host=localhost',
            'driver_options' => array(
                    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
            ),
    ),
    'service_manager' => array(
      'factories' => array(
         'Zend\Db\Adapter\Adapter' => function ($serviceManager) {
            $adapterFactory = new Zend\Db\Adapter\AdapterServiceFactory();
               $adapter = $adapterFactory->createService($serviceManager);

               \Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);

               return $adapter;
         }
      ),
   ),
);

1.1.2 config/autoload/global.php

(description:this is global profile file.)

<?php
/**
 * Global Configuration Override
 *
 * You can use this file for overriding configuration values from modules, etc.
 * You would place values in here that are agnostic to the environment and not
 * sensitive to security.
 *
 * @NOTE: In practice, this file will typically be INCLUDED in your source
 * control, so do not include passwords or other sensitive information in this
 * file.
 */

return array(
    // ...
    'service_manager' => array(
            'factories' => array(
                    'Zend\Db\Adapter\Adapter'
                    => 'Zend\Db\Adapter\AdapterServiceFactory',
            ),
    ),
);

1.2 model

data table is “Keyword”:

CREATE TABLE `pkrss_rsskeyword` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `key` varchar(32) NOT NULL,
 `count` int(11) NOT NULL,
 `type` char(4) NOT NULL DEFAULT 'r' COMMENT 'r:rss b:bookimage',
 PRIMARY KEY (`id`),
 UNIQUE KEY `key` (`key`,`type`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

and i used in module name “api”.

1.3 Module/Api/src/Api/Model/Keyword.php

(description:this is model data class.)

<?php
namespace Api\Model;

class Keyword
{
    public $id;
    public $key;
    public $count;
    public $type;

    public function exchangeArray($data)
    {
        $this->id     = (isset($data['id'])) ? $data['id'] : null;
        $this->key = (isset($data['key'])) ? $data['key'] : null;
        $this->count  = (isset($data['count'])) ? $data['count'] : null;
        $this->type  = (isset($data['type'])) ? $data['type'] : null;
    }
    
    public function toArray(){
        $ret = array();
        $ret['id'] = $this->id;
        $ret['key'] = $this->key;
        $ret['count'] = $this->count;
        $ret['type'] = $this->type;
        return $ret;
    }
}

1.4 Module/Api/src/Api/Model/KeywordTable.php

(description:this is model data table operator class.)

(i only test getkeywords function.)

<?php
namespace Api\Model;

use Zend\Db\TableGateway\TableGateway;
// use Zend\Console\Prompt\Select;
use Zend\Db\Sql\Select;

class KeywordTable
{
    protected $tableGateway;

    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
    }

    public function fetchAll()
    {
        $resultSet = $this->tableGateway->select();
        return $resultSet;
    }

    public function getKeywords($type,$start=0,$limit=1)
    {
        $start = (int)$start;
        $limit = (int)$limit;
        
        $rowset = $this->tableGateway->select(function(Select $selector) use ($start,$limit,$type){
            $selector->offset($start)
                    ->limit($limit)
                    ->order('count DESC')
                    ->where(array('type' => $type));
        });
        
        $ret = array();
        foreach ($rowset as $row) {
            $ret []= $row->toArray();
        }
        
        return $ret;
    }

    public function getKeyword($id)
    {
        $id = (int)$id;
        
        if(!$this->tableGateway->isInitialized())
            $this->tableGateway->initialize();
        
        $rowset = $this->tableGateway->select(array('id' => $id));
        $ret = $rowset->current();
        if($$ret)
          $ret = $ret->toArray();
        
        return $ret;
    }

    public function saveKeyword(Keyword $keyword)
    {
        $data = array(
                'id' => $keyword->id,
                'key' => $keyword->key,
                'count' => $keyword->count,
                'type' => $keyword->type,
        );

        $id = (int)$keyword->id;
        if ($id == 0) {
            $this->tableGateway->insert($data);
        } else {
            if ($this->getKeyword($id)) {
                $this->tableGateway->update($data, array('id' => $id));
            } else {
                throw new \Exception('Keyword id does not exist');
            }
        }
    }

    public function deleteKeyword($id)
    {
        $this->tableGateway->delete(array('id' => $id));
    }
}

1.5 Module/Api/src/Api/Controller/SearchController.php

(description:this is one sub controller,it call model and output with gzip compress json and no view render.)

<?php
namespace Api\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

/**
 * SearchController
 * @see http://framework.zend.com/manual/2.0/en/user-guide/database-and-models.html
 * @author liandeliang@gmail.com
 *
 * @version 1.0.0
 *
 */
class SearchController extends AbstractActionController
{
    protected $keywordTable;
    
    public function getKeywordTable()
    {
        if (!$this->keywordTable) {
            $sm = $this->getServiceLocator();
            $this->keywordTable = $sm->get('Api\Model\KeywordTable');
        }
        return $this->keywordTable;
    }
    
    /**
     * The default action - show the home page
     */
    public function indexAction()
    {
        // TODO Auto-generated SearchController::indexAction() default action
        return new ViewModel();
    }
    
    //public function nolayoutAction()
    //{
    //    $view = new ViewModel();
    //    $view->setTerminal(true);
    //    return $view;
   // }
    
    /**
     * example: http://localhost/book/public/api/search/list
     */
    public function listAction(){
        
        // get request param
        $type = $this->params('type','b');
        $start = (int)$this->params('start','0');
        $limit = (int)$this->params('limit','20');
    
        $table = $this->getKeywordTable();
        $result = $table->getKeywords($type,$start,$limit);
        
        \Application\View\Helper\OutputHelper::outputArray($result);
        
        // output json,and exit,then can no render view.
        exit();
        
        return false;
    }
}

2. mvc

2.1 screen shots:

image

2.1 module

module/Api/Module.php:

(description:this is module profile.)

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/Api for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Api;

// Add these import statements:
use Api\Model\Keyword;
use Api\Model\KeywordTable;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module implements AutoloaderProviderInterface
{
    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__ . '/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
            // if we're in a namespace deeper than one level we need to fix the \ in the path
                    __NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
                ),
            ),
        );
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function onBootstrap(MvcEvent $e)
    {
        // You may not need to do this if you're doing it elsewhere in your
        // application
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
    }
    
    // Add this method:
    public function getServiceConfig()
    {
        return array(
                'factories' => array(
                        'Api\Model\KeywordTable' =>  function($sm) {
                            $tableGateway = $sm->get('KeywordTableGateway');
                            $table = new KeywordTable($tableGateway);
                            return $table;
                        },
                        'KeywordTableGateway' => function ($sm) {
                            $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
                            $resultSetPrototype = new ResultSet();
                            $resultSetPrototype->setArrayObjectPrototype(new Keyword());
                            return new TableGateway('pkrss_rsskeyword', $dbAdapter, null, $resultSetPrototype);
                        },
                ),
        );
    }
}

2.2 module config:

module/Api/config/module.config.php:

(description:this is module router profile.)

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Api\Controller\Search' => 'Api\Controller\SearchController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'api' => array(
                'type'    => 'Literal',
                'options' => array(
                    // Change this to something specific to your module
                    'route'    => '/api',
                    'defaults' => array(
                        // Change this value to reflect the namespace in which
                        // the controllers for your module are found
                        '__NAMESPACE__' => 'Api\Controller',
                        'controller'    => 'search',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // This route is a sane default when developing a module;
                    // as you solidify the routes for your module, however,
                    // you may want to remove it and replace it with more
                    // specific routes.
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'Api' => __DIR__ . '/../view',
        ),
    ),
);

2.3 view helper

module/Application/src/Application/View/Helper/OutputHelper.php:

(description:this is output with json and gzip detect.)

<?php
/**
 * Application
 * 
 * @author
 * @version 
 */
namespace Application\View\Helper;

use Zend\View\Helper\AbstractHelper;

class ArrayToXML
{
    /**
     * The main function for converting to an XML document.
     * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
     *
     * @param array $data
     * @param string $rootNodeName - what you want the root node to be - defaultsto data.
     * @param SimpleXMLElement $xml - should only be used recursively
     * @return string XML
     */
    public static function toXml($data, $xmlDoc, $xmlNode=null)
    {
        // loop through the data passed in.
        foreach($data as $key => $value)
        {
            if (is_numeric($key))
            {
                // make string key...
                $key = 'item';
            }

            // if there is another array found recrusively call this function
            if (is_array($value))
            {
                $xmlNode2 = $xmlNode->appendChild($xmlDoc->createElement($key));
                    
                ArrayToXML::toXml($value, $xmlDoc, $xmlNode2);
            }
            else
            {
                $xmlTextNode = $xmlDoc->createTextNode($value);
                $xmlUrlNode = $xmlDoc->createElement($key);
                $xmlUrlNode->appendChild($xmlTextNode);
                $xmlNode->appendChild($xmlUrlNode);
            }
        }
    }
}

$log_file = null;
/**
 * OutputHelper Action Helper
 *
 * @uses actionHelper Zend_Controller_Action_Helper
 */
/**
 * View Helper
 */
class OutputHelper extends AbstractHelper
{

    public function __invoke($in)
    {
        // TODO Auto-generated OutputHelper::__invoke
        return $in;
    }

    public static function outputErrorMessage($code = -1,$msg = "Error"){
        self::outputArray(array('code' => $code, 'message' => $msg));
        exit();
    }

    public static function log($output){
        global $log_file;
        if(!$log_file)
            $log_file = fopen('1.txt','w');
        if($log_file)
            fwrite($log_file,$output  . "\r\n");
    }

    public static function outputArray($output,$type = 'json'){
        $ret = self::getDataFromArray($output,$type);
        return self::outputData($ret,$output);
    }

    public static function outputData($output,$type){
        //header('Access-Control-Allow-Origin: *');

        if ($type=='xml') {
            header("Content-Type: text/xml");
        } else if ($type=='js') {
            header("Content-type: application/x-javascript");
        } else if ($type=='txt') {
            header("Content-type: text/plain");
        }    else {
            header("Content-type: application/json");
        }

        return self::ob_echo($output);
    }

    public static function getDataFromArray($output,$type){

        if ($type=='xml') {
            $xmlDoc = new DOMDocument("1.0","utf-8");
            $xmlNode = $xmlDoc->appendChild($xmlDoc->createElement("items"));

            ArrayToXML::toXml($output, $xmlDoc, $xmlNode);

            $xmlDoc->formatOutput = true;
            return $xmlDoc->saveXml();
        }else if ($type=='js') {
            return @json_encode($output); // 'var result=' .
        }else if ($type=='htm') {
            return $output; // 'var result=' .
        } else {
            return @json_encode($output);
        }
    }

    public static function is_gzip(){
        if(defined('PKRSS_DEBUG') && PKRSS_DEBUG)
            return false;
        if(empty($_SERVER['HTTP_ACCEPT_ENCODING']))
            return false;
        return substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
    }

    public static function ob_echo($content){
        if (self::is_gzip())
            ob_start("ob_gzhandler");
        else
            ob_start();
        echo $content;
        ob_end_flush();

        return $content;
    }
}


class UtilsHelper {
    public static function getPost($name){
        if(defined('PKRSS_DEBUG') && PKRSS_DEBUG)
            return self::getParam($name);
        if(isset($_POST[$name]))
            return $_POST[$name];
        return null;
    }

    public static function getGet($name){
        if(isset($_GET[$name]))
            return $_GET[$name];
        return null;
    }

    public static function getParam($name){
        if(isset($_GET[$name]))
            return $_GET[$name];
        else if(isset($_POST[$name]))
            return $_POST[$name];
        return null;
    }

    public static function getReferHost(){
        if(defined('PKRSS_DEBUG') && PKRSS_DEBUG){
            return '';
        }

        if(!isset($_SERVER["HTTP_REFERER"]) || empty($_SERVER["HTTP_REFERER"]))
            OutputHelper::outputErrorMessage(-1,'http header referer checked fail!');
        $url = $_SERVER["HTTP_REFERER"];
        return parse_url($url, PHP_URL_HOST);
    }

    public static function safe_require($file){
        if(file_exists($file)){
            require $file;
            return true;
        }
        return false;
    }

}