Music store Deployed on zend frame work , after deploying from git repository I get these errors
These errors are way too many and i am a noob with frameworks . please help me !!!
( ! ) Fatal error: Uncaught exception
'Zend\ModuleManager\Exception\RuntimeException' with message 'Module
(Application) could not be initialized.' in
C:\xampp\htdocs\albumzend\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php
on line 189 ( ! ) Zend\ModuleManager\Exception\RuntimeException:
Module (Application) could not be initialized. in
C:\xampp\htdocs\albumzend\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php
on line 189 Call Stack
# Time Memory Function Location 1 0.0010 135312 {main}( ) ..\index.php:0 2 0.0270 266752 Zend\Mvc\Application::init(
) ..\index.php:17
3 0.1630 1117408 Zend\ModuleManager\ModuleManager->loadModules(
) ..\Application.php:252
4 0.1630 1117592 Zend\EventManager\EventManager->trigger(
) ..\ModuleManager.php:109
5 0.1630 1117776 Zend\EventManager\EventManager->triggerListeners(
) ..\EventManager.php:207 6 0.1670 1131560 call_user_func (
) ..\EventManager.php:468
7 0.1670 1131576 Zend\ModuleManager\ModuleManager->onLoadModules(
) ..\EventManager.php:468
8 0.1670 1131912 Zend\ModuleManager\ModuleManager->loadModule(
) ..\ModuleManager.php:90
9 0.1670 1132064 Zend\ModuleManager\ModuleManager->loadModuleByName(
) ..\ModuleManager.php:163
MY APPLICATION.PHP
<?php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'Application',
'Musicstore',
),
// These are various options for the listeners attached to the ModuleManager
'module_listener_options' => array(
// This should be an array of paths in which modules reside.
// If a string key is provided, the listener will consider that a module
// namespace, the value of that key the specific path to that module's
// Module class.
'module_paths' => array(
'./module',
'./vendor',
),
// An array of paths from which to glob configuration files after
// modules are loaded. These effectively override configuration
// provided by modules themselves. Paths may use GLOB_BRACE notation.
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
// Whether or not to enable a configuration cache.
// If enabled, the merged configuration will be cached and used in
// subsequent requests.
//'config_cache_enabled' => $booleanValue,
// The key used to create the configuration cache file name.
//'config_cache_key' => $stringKey,
// Whether or not to enable a module class map cache.
// If enabled, creates a module class map cache which will be used
// by in future requests, to reduce the autoloading process.
//'module_map_cache_enabled' => $booleanValue,
// The key used to create the class map cache file name.
//'module_map_cache_key' => $stringKey,
// The path in which to cache merged configuration.
//'cache_dir' => $stringPath,
// Whether or not to enable modules dependency checking.
// Enabled by default, prevents usage of modules that depend on other modules
// that weren't loaded.
// 'check_dependencies' => true,
),
// Used to create an own service manager. May contain one or more child arrays.
//'service_listener_options' => array(
// array(
// 'service_manager' => $stringServiceManagerName,
// 'config_key' => $stringConfigKey,
// 'interface' => $stringOptionalInterface,
// 'method' => $stringRequiredMethodName,
// ),
// )
// Initial configuration with which to seed the ServiceManager.
// Should be compatible with Zend\ServiceManager\Config.
// 'service_manager' => array(),
);
INDEX.PHP module>musicstore>ablums>index.php
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('Asia/Kolkata');
// directory setup and class loading
set_include_path('.' . PATH_SEPARATOR . '/xampp/htdocs/albumzend/library/'
. PATH_SEPARATOR . '/xampp/htdocs/albumzend/application/models/albums'
. PATH_SEPARATOR . '/xampp/htdocs/albumzend/application/forms/albums'
. PATH_SEPARATOR . get_include_path());
include "Zend/Loader/Autoloader.php";
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Models');
$loader->setFallbackAutoloader(true);
$loader->suppressNotFoundWarnings(false);
$view = new Zend_View();
$view->addHelperPath("ZendX/JQuery/View/Helper", "ZendX_JQuery_View_Helper");
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
// load configuration
$config = new Zend_Config_Ini('/xampp/htdocs/albumzend/application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
// setup database
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
$registry->set('db', $db);
// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('/xampp/htdocs/albumzend/application/controllers');
Zend_Layout::startMvc(array('layoutPath'=>'/xampp/htdocs/albumzend/application/layouts'));
// run!
$frontController->dispatch();
?>
MY APPLICATION
module>musicstore>application>configs>Application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "xampp/htdocs/albumzend/library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
File Struct:
http://i58.tinypic.com/2uqcbpv.png
Git Repository : https://github.com/srish/Music-Store.git
In your git i dont see public directory with index.php file that initiates the zend-framework application, i see you mover it to the albums/index.php but there once more its not the file given by automatic project generator for zend-framework 1.12
I have one idea for you. Download the newest ZF 1 (now its 1.12, not 1.8 from 2008 year) and then try recreating your project once more. It will work better as there were several huge changes in performance and even framework that have huge positive impact.
PS: in the index.php file that initiates the ZF - you should not make any changes. Try to make them in Bootstrap.php in application directory.
Related
So basically I just installed Phalcon 2.0 on my ubuntu machine, with apache2, mysql and all the stuff installed. I went straight into the documentation of Phalcon to get me started. After following the exact steps from their tutorial, I got this error:
Fatal error: Class 'Users' not found in /var/www/html/phalcon/tutorial/app/controllers/SignupController.php on line 14
I think it may be related to namespacing of classes and stuff like that, but I wasn't able to figure it out so far.
Looks like you didn't register your folders properly. I add a resume of my code to give you an idea.
File index.php
use Phalcon\Mvc\Micro;
use Phalcon\Events\Manager as EventsManager;
define('APP_DIR', dirname(__DIR__) .'/');
try {
$config = require APP_DIR .'config/config.php';
require APP_DIR .'config/loader.php';
...
} catch (Exception $e) {}
File config.php
return new Phalcon\Config([
'application' => [
'environment' => 'development',
'controllers' => APP_DIR .'controllers/',
'library' => APP_DIR .'library/',
'models' => APP_DIR .'models/',
'plugins' => APP_DIR .'plugins/',
'routes' => APP_DIR .'routes/',
'logs' => APP_DIR .'logs/',
'base_uri' => '/',
'debug' => false
]
]);
File loader.php
<?php
$loader = new \Phalcon\Loader;
// Register directories
$loader->registerDirs([
$config->application->controllers,
$config->application->library,
$config->application->models,
$config->application->plugins,
])->register();
// Composer autoloader
require_once APP_DIR .'vendor/autoload.php';
This should resolve any class specified in config folders.
I have a zend project which makes use of doctrine2.
My problem is that I can't disable errors with sensitive data. (i.e. when database connection fails an error is shown including the password).
What I have tried so far is changing the index.php file in the public folder as follows:
<?php
//Disable all error reporting
error_reporting(0); //Somehow this doesn't work
ini_set('display_errors', false); //Somehow this doesn't work
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
return false;
}
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
try{
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
}
catch(Exception $ex){
echo 'server error!';//This code is never reached although a PDOException is thrown!
}
What do I need to do to disable these kind of errors and hide sensitive data?
Check this out -> http://www.php.net/manual/en/pdo.connections.php Particularly the Warning Notice.
Using a Try / Catch in the index file isn't going to work for you. You'll need to put that into your Service Layer or where-ever else you are doing your DB Queries at (you didn't supply this code example).
You can also in your module.config.php file set:
'display_exceptions' => false
Also pay attention to the Exception handler you are using as different one could return different information.
Seems I had to change the view_manager configuration in my_project_folder/module/Application/config/module.config.php, by setting display_exceptions to false:
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => false, //This line did the trick!
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.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',
),
),
EDIT: Didn't catch that this was ZEND 2. See my last comment below.
I am guessing the error level reporting is set with this line
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
which is after you turn it off, so it is simply getting switched back on again.
Try this in application.ini
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
resources.frontController.throwExceptions = 0
resources.frontController.params.displayExceptions = 0
Everytime I receive an error in Zend Framework 2, I get just 500 Internal Server Error displayed and have to search through the Zend Server error log.
I've tried putting this to my config/autoload/local.php file but it doesn't work:
return array(
'phpSettings' => array(
'display_startup_errors' => true,
'display_errors' => true,
),
);
There is no native support for that in zf2 (afaik). You'd either have to set them in php.ini itself, or set them in index.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
If you really want to be able to supply them as config settings, you could keep what you have and do that in a module bootstrap, get them from config, and call ini_set() on each key value pair
public function onBootstrap(EventInterface $e) {
$app = $e->getApplication();
$sm = $app->getServiceManager();
$config = $sm->get('Config');
$phpSettings = isset($config['phpSettings']) ? $config['phpSettings'] : array();
if(!empty($phpSettings)) {
foreach($phpSettings as $key => $value) {
ini_set($key, $value);
}
}
}
Edit: as #akond rightly points out in the comments, you could just add the ini_set lines to local.php which is a better solution.
To easilly configure phpSettings on your ZF2 app, you should consider using DluPhpSettings.
With this module, you can configure your settings for each environment you have:
/* Local application configuration in /config/autoload/phpsettings.local.php */
<?php
return array(
'phpSettings' => array(
'display_startup_errors' => false,
'display_errors' => false,
'max_execution_time' => 60,
'date.timezone' => 'Europe/Prague',
'mbstring.internal_encoding' => 'UTF-8',
),
);
Look this blog post for more info too!
I have following code :
in application.ini
cache.default.adapter = "memcached"
cache.default.params.host = "localhost"
cache.default.params.port = "11211"
in Bootstrap.php
$cache = new Memcache();
$cache->connect($cache_params['host'], $cache_params['port']);
Zend_Registry::set("cache", $cache);
and also I am having memcache installed on my machine by putting php_memcache.dll in wamp\bin\php\php5.3.9\ext and also extension=php_memcache.dll in php.ini
But still I am getting the following error :
( ! ) Fatal error: Class 'Memcache' not found in \wamp\www\projectname\application\Bootstrap.php on line 160
I have gone through google but still not able to solved the problem. What is the problem why it's not connecting to the memcache.
You are trying to cache your database?
You want to use Zend_Cache.
(From: http://zendcoding.com/how-to-use-memcached-in-the-zend-framework)
$frontendOpts = array(
'caching' => true,
'lifetime' => 1800, //how long in seconds to keep the cache for.
'automatic_serialization' => true //In order to store objects and arrays, Zend must first serialize data into a string. If this parameter is set to ‘true‘, this serialization will happen on the fly and behind the scenes.
);
$backendOpts = array(
'servers' =>array(
array(
'host' => $cache_params['host'],
'port' => $cache_params['port'],
'weight' => 1
)
),
'compression' => false
);
$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);
This link also demonstrates how to load and update the cache, and how to make it accessible from everywhere in your application. A good read, to be sure.
Your setting is memcached
cache.default.adapter = "memcached"
but you want to use memcache
$cache = new Memcache();
Try this example
<?php
$mc = new Memcached('mc');
$mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
if (!count($mc->getServerList())) {
$mc->addServers(array(
array('127.0.0.1',11211),
array('127.0.0.1',11211),
));
}
$key = 'mykey';
$mc->add($key,'test for memcached not memcache');
$val = $mc->get($key);
echo $val;
?>
In my Zend Framework project, I am using some custom resource types that I add to the resource loader in my application's Bootstrap.php file.
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoloader()
{
$resourceLoader = $this->getResourceLoader();
$resourceLoader->addResourceTypes(array(
'infrastructure' => array(
'namespace' => 'Infrastructure',
'path' => 'infrastructure/',
),
'interfaces' => array(
'namespace' => 'Interface',
'path' => 'interfaces/',
),
'default' => array(
'namespace' => '',
'path' => '/',
),
));
}
...
}
I can autoload these resources okay when running the application, but when running PHPUnit and trying to load these classes during tests, they cannot be found.
PHP Fatal error: Class 'Wbp_Infrastructure_Persistence_InMemory_TagRepository' not found in /var/www/worldsbestprizes/tests/library/Mbe/Validate/TaggedUriTest.php on line 37
The tests/bootstrap.php file looks like this.
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Mbe_');
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
Is there something I should add to it to allow those custom resource types to be loaded?
You need to register the Wbp_ namespace in a similar method to what you're doing in the tests/bootstrap.php file:
$autoloader->registerNamespace('Wbp_');