Trouble with ZFTool: Module (ZFTool) could not be initialized - php

ZFTool is the maintenance tool for Zend Framework applications. There are several ways to install it. I use it from a PHAR file.
$ mkdir -p /usr/lib/ZendFramework/zftool
$ cd /usr/lib/ZendFramework/zftool
$ wget http://packages.zendframework.com/zftool.phar
$ ln -s /usr/lib/ZendFramework/zftool/zftool.phar /usr/bin/zf
$ chmod 755 /usr/bin/zf
It works, when I execute the tool outside of a ZF application. But now I tried this whithin an application and get this error:
root#devvm:/usr/lib/ZendFramework/test# cd /path/to/application/ root#devvm:/path/to/application# zf PHP Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZFTool) could not be initialized.' in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:175 Stack trace:
#0 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('ZFTool')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php( in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 175
Why does it happen? How to avoid this behavior?

It appears you need to install zftool into your project. user2900416 kind of hinted at this, but I think it is more correct to install zftool using composer like so for each project:
composer.phar require zendframework/zftool:dev-master
This solved it for me. It is discussed in an issue here: https://github.com/zendframework/ZFTool/issues/51

Check the case of the module.php file:
Make sure your **M**odule.php file is written with a capital M otherwise the file may not be found. This took me a day to bug test so I really hope I save someone the same trouble!

I got the same problem. This is what I did to fix it with 2 steps:
(1) Download ZFTool zipball as suggested by manual installation at http://framework.zend.com/manual/2.1/en/modules/zendtool.introduction.html.
(2) Unzip the zipball under your application's module/ directory with directory name as ZFTool/.
Then, the Module(ZFTool) has been installed in your application and can be initialized by either invoking
"zftool.phar create module ModuleName"
or
"zf.php create module ModuleName" where zf.php is in the zipball.
It looks REALLY stupid to copy the ZFTool module inside each application but I have spent days in trying to find a better one without any luck.n Hope someone can propose one.

Related

codeigniter 4 running error first time with xampp

Uncaught Error: Call to undefined function CodeIgniter\locale_set_default()
in C:\xampp\htdocs\sunpay-ci4\system\CodeIgniter.php:184
Stack trace:
#0 C:\xampp\htdocs\sunpay-ci4\system\bootstrap.php(181): CodeIgniter\CodeIgniter->initialize()
#1 C:\xampp\htdocs\sunpay-ci4\public\index.php(36): require('C:\\xampp\\htdocs...')
#2 {main} thrown in C:\xampp\htdocs\sunpay-ci4\system\CodeIgniter.php on line 184
I don't understand this error, the first page works if I drop this package.
Try opening php.ini from the control panel:
Apache row -> Config -> php.ini
Then enable intl extension by removing ; in front of extension=intl
Edit: the reason it fails is because the intl extension is disabled by default in xampp
Recently I stuck on the same problem on CI version 4.0.4.
Follow the steps to fix it.
Click on "config" from the xampp control panel.
Then click on php.ini option.
Then it will open on your default text editor application (for me it is Notepad). then click on find option.
Then search for ";extension=intl".
replace ";extension=intl" with "extension=intl".
That's all. Thanks.
get your php version by put this code : phpinfo();die(); in your index.php after <?php so it looks like like <?php phpinfo();die();
PHP Version 7.2.24-0ubuntu0.18.04.7
jump to /etc/php/{your php version}/apache2 folder; example : /etc/php/7.2/apache2 and open php.ini then find ;extension=intl and remove the semicolon ;
open your terminal then write or copy paste this command sudo systemctl restart apache2 and press ENTER
open your CI 4 again in your browser.
Welcome to CodeIgniter 4.0.4
The small framework with powerful features
==============================================================================
if you still get the same error please try to install intl extension using this command in your terminal:
sudo apt install php{your php version}-intl
sudo systemctl restart apache2`
example :
sudo apt install php7.2-intl
sudo systemctl restart apache2
open your CI 4 again in your browser.
Welcome to CodeIgniter 4.0.4
The small framework with powerful features
=============================================================================
#NB :
dont forget to remove phpinfo();die(); in the first step
sorry for my bad english
Just go to the mentioned line in display in error.
C:\xampp\htdocs\sunpay-ci4\system\CodeIgniter.php:184
You can find it here: root folder/system/CodeIgniter.php
on line no 184 you will find the below code.
locale_set_default($this->config->defaultLocale ?? 'en');
just comment it like this.
#locale_set_default($this->config->defaultLocale ?? 'en');
Now, the code is working.
1.search for intl and uncomment this extension in php.ini file by removing ; from begin of line extension=intl
2. restart Apache service by stop and starting it again from xampp control panel
When i started a new project i got this error on welcome screen. Fatal error: Uncaught Error: //pp\Views\welcome_message.php:222 Stack trace: #0 {main} thrown in. It appears like there is a problem with the installation of codeigniter but in fact it is an echo error in line 222 of the welcom_message.php page go there an remove the <?= CodeIgniter\CodeIgniter::CI_VERSION ?> from line 222 it should look like this
<div class="heroe">
<h1>Welcome to CodeIgniter </h1>
<h2>The small framework with powerful features</h2>
</div>
Then it will echo hello screen correctly
Usually to get round this try these three points:
Ensure .writable folder is writable with file permissions 0777 (must have leading zero)
Try setting the following in index.php -> $_SERVER['CI_ENVIRONMENT'] = 'development'; and toggle with $_SERVER['CI_ENVIRONMENT'] = 'production' in .env file;
Access this file(CodeIgniter.php) in the following directory: project_folder/vendor/codeigniter4/framework/system/CodeIgniter.php
public function initialize()
{
if( function_exists('locale_set_default' )):
locale_set_default($this->config->defaultLocale ?? 'en');
endif;}
if your have installed Apache, PHP, MYSQL manually, then set locale to app in .env file:
app.locale = "en"
save and restart apache service

Using PHPUnit in PhpStorm using Docker

I have a very specific configuration that I have to hold until I can start moving feature from my old PHP 5 application to somewhere else.
I'm trying to tie my testing environment with PhpStorm but I cant figure it out. Since I'm not using Composer, I have to specify phpunit.phar path (which is /usr/local/bin/phpunit - a symlink to /usr/local/bin/phpunit.phar). I keep having this error.
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot create phar '/usr/local/bin/phpunit', file extension (or combination) not recognised or the directory does not exist' in /opt/.phpstorm_helpers/phpunit.php:181
Stack trace:
#0 /opt/.phpstorm_helpers/phpunit.php(181): Phar->__construct('/usr/local/bin/...')
#1 /opt/.phpstorm_helpers/phpunit.php(250): IDE_PHPUnit_Loader::init()
#2 {main}
thrown in /opt/.phpstorm_helpers/phpunit.php on line 181
The setup on my Docker is
PHP 5.5.9 with PHPUnit 4.8.9
My remote Docker PHP interpreter works in PhpStorm, and my PHPUnit works when I run test in bash (using docker exec phpunit) - so it seems that the pieces are working, mostly the glue doesn't work.
Here are my settings
I just ran into this problem with composer and the issue is you need to set up a PHPUnit interpreter in PHPStorm with the autoload.php file.
Open Settings > Languages & Frameworks > PHP > Test Frameworks
Click the Plus + icon to add a Remote Interpreter
Select the CLI interpreter previously defined and use existing path mappings
Select Use Composer Autoloader
Path to script should be /path/to/vendor/autoload.php
Check off Default configuration file and set it to /path/to/phpunit.xml
I also needed to have the following section in my docker-compose.yml:
services:
my-api:
# Other contents omitted
environment:
- PHP_IDE_CONFIG=serverName=my-api.company.com
Where my-api.company.com is the server definition name from Settings > Languages & Frameworks > PHP > Servers

Yii2 Testing error while codeception run command is issued

I've got a test suite in yii2 that I would like to run, I have installed composer, codeception, built the test with 'codecept build' and so far so good, everything was smooth as butter until I've issued the command 'codecept run'; it throws an error which by any means I have tried to figured out unfortunately unsuccessfully. I have reinstalled composer, clear the composer cache, rebuilt the project again with codecept build but not success whatsoever.
The error is as follows:
MyApp\tests.functional Tests (4) -----------------------------------------------------------------
- HomeCest: Check open<pre>PHP User Error 'yii\base\ErrorException' with message 'Exception 'yii\base\InvalidParamException' with message 'The file or directory to be published does not exist: /home/user/GIT_MyApp/yii/myapp/vendor/bower/jquery/dist'
in /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php:453
Stack trace:
#0 /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetBundle.php(185): yii\web\AssetManager->publish('/home/angelo/GI...', Array)
#1 /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php(268): yii\web\AssetBundle->publish(Object(yii\web\AssetManager))
#2
/home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php(239): yii\web\AssetManager->loadBundle('yii\\web\\JqueryA...', Array, true)
.....
.....
The weirdest thing though, is that the same project runs fine in another machine (CENT OS). Mine is Kubuntu 16.04. Could it be the machine?
Could someone please tell me what is happening and why this error keeps on coming?
You have to install fxp/composer-asset-plugin with composer globally:
composer global require "fxp/composer-asset-plugin:~1.3.1"
Like here: https://github.com/yiisoft/yii2-app-basic/blob/2.0.12/.travis.yml#L20

Symfony is suddenly failing with "The service "session.storage.metadata_bag" has a dependency on a non-existent parameter"

I upgraded from Symfony 3.1.5 to 3.2.0 yesterday morning and everything was fine up until an hour or so ago.
Now Symfony throws the following exception upon any type of access, including console commands:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "session.storage.metadata_bag" has a dependency on a
non-existent parameter "session.metadata.storage_key".
I have tried the following:
Backed out my most recent changes
Deleted var/cache/*
Here is the exception trace:
Exception trace:
() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php:56
Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:217
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveString() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:187
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:177
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php:39
Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass->process() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:120
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:565
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:484
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:116
Symfony\Component\HttpKernel\Kernel->boot() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
Symfony\Component\Console\Application->run() at /Volumes/Data01/Projects/Beck/WWUI/site/bin/console:29
As you can see, it's part of Symfony, and not my code.
I am at a loss.
Has anybody else seen this?
Suggestions?
Edit 1:
Based on Dagon's suggestion that I check session.xml, and seeing that it appears correct, I decided to replace the
<argument>%session.metadata.storage_key%</argument>
tag with
<argument>_sf2_meta</argument>
in session.xml. This resulted in a new, similar error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service
"64e3c91c625381e3c2c0184cf9ea0c6d5353986d77aa111949ca6fb8b17a8f07_2"
has a dependency on a non-existent parameter "validator.mapping.
cache.prefix".
This isn't really an answer per-se, but is is a fix.
I renamed vendor to vendor-HOLD and then ran composer install. Problem gone.
I did a diff on the old and new session.xml files and found that the definition of the parameter was different. The version causing the error contained:
<parameter string="session.metadata.storage_key">_sf2_meta</parameter>
The newly installed version contained:
<parameter key="session.metadata.storage_key">_sf2_meta</parameter>
instead. Obviously other files were incorrect, as well, based on the experimental edit I did to session.xml. No clue as to what happened, but it's nice that composer install fixed it. Oh, and yes, I deleted vendor-HOLD afterwards.

Magento Cron Job fails while DLO not loaded

I am trying to run the Magento Cron job but get this error message. I checked phpinfo() which shows everything should be loaded and the get_loaded_extensions() shows => PDO [27] => pdo_mysql [28] => pdo_sqlite [29]
Any thoughts what I can do next to find the cause?
Thanks,
Chris
PHP Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with
message 'The PDO extension is required for this adapter but the extension is
not loaded' in /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Pdo/Abstract.php:342
Stack trace:
#0 /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Abstract.php(248):
Zend_Db_Adapter_Pdo_Abstract->setFetchMode(2)
#1 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource.php(175):
Zend_Db_Adapter_Abstract->__construct(Array)
#2 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource.php(110):
Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element))
#3 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320):
Mage_Core_Model_Resource->getConnection('core_write')
#4 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract
in /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Pdo/Abstract.php
on line 342
Probably you are checking the phpinfo() from the browser, but the extension might be loaded just for apache/nginx, and not for commandline, which is how I'm assuming the cronjob php file will run.
Check that the extension is enabled for CLI, typically in the following location:
/etc/php5/cli/conf.d/20-pdo_mysql.ini (the name might not be exactly the same)
It might be only on /etc/php5/apache2/ or /etc/php5/php-fpm/
You can just copy it from the other locations or create a new file with the following content:
extension=pdo_mysql.so
After that check that the extension is loaded by running from command-line:
php -i | grep pdo
If it's loaded you should see some output and the cronjob should now work.
I hope it helps.
Use "$ which php" to ensure you're using the PHP you think you are.
Look at the php.ini your command line PHP is using and see if any extensions are disabled
An alternate method is to have Apache run the cron jobs by using wget:
[specified time] wget -q http://magento.url.com/cron.php
Using this method also helps in cases where file permissions are an issue (specially when Magento's cache is involved).

Categories