Tuesday, March 11, 2014

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

Monday, March 10, 2014

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!

Saturday, March 8, 2014

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!

Friday, March 7, 2014

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 !