I keep getting this error on Slim 4 after installing new version 4.12 - slim

I keep getting this error Slim Application Error after installing the new Slim 4 framework.
I tried switching back to old version of slim but I keep getting the same thing.
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
/**
* Instantiate App
*
* In order for the factory to work you need to ensure you have installed
* a supported PSR-7 implementation of your choice e.g.: Slim PSR-7 and a supported
* ServerRequest creator (included with Slim PSR-7)
*/
$app = AppFactory::create();
// Add Routing Middleware
$app->addRoutingMiddleware();
/*
* Add Error Handling Middleware
*
* #param bool $displayErrorDetails -> Should be set to false in production
* #param bool $logErrors -> Parameter is passed to the default ErrorHandler
* #param bool $logErrorDetails -> Display error details in error log
* which can be replaced by a callable of your choice.
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
// Define app routes
$app->get('/hello/{name}', function (Request $request, Response $response, $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
// Run app
$app->run();
Output:
Slim Application Error
The application could not run because of the following error:
Details
Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 91
Trace:
#0 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(57): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request))
#1 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner))
#2 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(89): class#anonymous->handle(Object(Slim\Psr7\Request))
#3 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/MiddlewareDispatcher.php(132): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(class#anonymous))
#4 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/MiddlewareDispatcher.php(73): class#anonymous->handle(Object(Slim\Psr7\Request))
#5 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/App.php(206): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request))
#6 /opt/lampp/htdocs/MyocappAPI/vendor/slim/slim/Slim/App.php(190): Slim\App->handle(Object(Slim\Psr7\Request))
#7 /opt/lampp/htdocs/MyocappAPI/public/index.php(41): Slim\App->run()
#8 {main}

I'm glad OP figured it out, but he didn't share his solution so here is what worked for me:
$app = AppFactory::create();
$app->setBasePath("/slimapp/public/index.php");
where the full path to my starter page is:
C:\xampp\htdocs\slimapp\public\index.php
To test my starter page, the URL I used was:
localhost/slimapp/public/index.php/hello/Beautiful
I think in Slim 3 you didn't need to manually set the base path, but you do in Slim 4. I don't know if it's a bug but this worked.

Slim 4 has some bugs in routing. So,Downgrade the slim version to 3.*
Reference:
https://discourse.slimframework.com/t/slim-4-httpnotfoundexception/3273/18

Related

There is no device with ID Using Zend and WURFL

I have integrate WURFL 1.6.0 with Zend every thing goes smooth it detects the desktop but in case of Android i am getting this error .On digging in deep i found out that my dir data/wurfl/cache is not loading with any data i have given it 777 permission but still it didnt work.
[25-Jun-2015 09:39:09] PHP Fatal error:
Uncaught exception 'Exception' with message 'There is no device with ID [generic_android_ver4_4] in the loaded WURFL Data' in /var/www/vhosts/mobiletocash.co.uk/httpdocs/library/wurfl-php-1.6.0.1/WURFL/CustomDeviceRepository.php:108
Stack trace:
#0 /var/www/vhosts/mobiletocash.co.uk/httpdocs/library/wurfl-php-1.6.0.1/WURFL/CustomDeviceRepository.php(211): WURFL_CustomDeviceRepository->getDevice('generic_android...')
#1 /var/www/vhosts/mobiletocash.co.uk/httpdocs/library/wurfl-php-1.6.0.1/WURFL/WURFLService.php(146): WURFL_CustomDeviceRepository->getDeviceHierarchy('generic_android...')
#2 /var/www/vhosts/mobiletocash.co.uk/httpdocs/library/wurfl-php-1.6.0.1/WURFL/WURFLService.php(62): WURFL_WURFLService->getWrappedDevice('generic_android...', Object(WURFL_Request_GenericRequest))
#3 /var/www/vhosts/mobiletocash.co.uk/httpdocs/library/wurfl-php-1.6.0.1/WURFL/WURFLManager.php(90): WURFL_WURFLService->getDeviceForRequest(Object(WURFL_Request_GenericRequest))
#4 /var/www/vhosts/mobiletocash.co.uk/httpdocs/library in /var/www/vhosts/mobiletocash.co.uk/httpdocs/library/wurfl-php-1.6.0.1/WURFL/CustomDeviceRepository.php on line 108
$resourcesDir = dirname(__FILE__) . '/../../data/wurfl/';
$wurfl['main-file'] = $resourcesDir . 'wurfl.xml';
$wurfl['patches'] = array($resourcesDir . 'web_browsers_patch.xml');
$cache['provider'] = 'Null';
//
$persistence['provider'] = 'File';
$persistence['dir'] = $resourcesDir . '/cache/';
$configuration['wurfl'] = $wurfl;
$configuration['persistence'] = $persistence;
$configuration['cache'] = $cache;
if i give $cache['provider'] = null;
it throws another exception . tried using $persistence['provider'] = 'file'; but no use
From what I can tell it does not look like the WURFL file is being properly loaded (perhaps the directory is not writeable) or is out of date. You most likely need to delete the persistence directory and reload the WURFL API.

Extbase can't use external PHP library

I am building a simple extension to display information on a Google Maps with Typo3.
I want to use the following PHP class (http://www.ycerdan.fr/developpement/google-maps-api-v3/) but I can't use it in my Controller.
I tried to use autoloading and require_once in my controller, but I just get PHP or Typo3 errors.
I guess it's a trivial problem, but I can't make it work despite lot of time searching.
Any help or hint are greatly appreciated ;)
General infos
Vendor name : CLICmap
Extension name : clicmap
Class location : Resources/Private/PHP
ext_autoloader.php :
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('clicmap');
return array(
'gmaps' => $extensionPath.'Resources/Private/PHP/GoogleMapAPIv3.class.php',
);
How I use it in my controller
public function listAction() {
$maps = $this->mapRepository->findAll();
$gmaps = $this->objectManager->get('gmaps');
$this->view->assign('maps', $maps);
}
The PHP error :
Uncaught TYPO3 Exception
#1289386765: Could not analyse class:gmaps maybe not loaded or no autoloader? (More information)
TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException thrown in file
/var/www/html/ftypo3/typo3/sysext/extbase/Classes/Object/Container/ClassInfoFactory.php in line 37.
Trying require_once :
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('clicmap');
require_once($extensionPath . 'Ressources/Private/PHP/GoogleMapAPIv3.class.php');
I get the following PHP error :
Warning: Uncaught exception 'TYPO3\CMS\Core\Error\Exception' with message 'PHP Warning: require_once(/var/www/html/ftypo3-fluid/typo3conf/ext/clicmap/Ressources/Private/PHP/GoogleMapAPIv3.class.php): failed to open stream: No such file or directory in /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php line 52' in /var/www/html/ftypo3/typo3/sysext/core/Classes/Error/ErrorHandler.php:101 Stack trace: #0 /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php(52): TYPO3\CMS\Core\Error\ErrorHandler->handleError(2, 'require_once(/v...', '/var/www/html/f...', 52, Array) #1 /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php(52): CLICmap\Clicmap\Controller\MapController::listAction() #2 [internal function]: CLICmap\Clicmap\Controller\MapController->listAction() #3 /var/www/html/ftypo3/typo3/sysext/extbase/Classes/Mvc/Controller/ActionController.php(286): call_user_func_array(Array, Array) #4 /var/www/html/ftypo3/typo3/sysext/extbase/Classes/Mvc/ in /var/www/html/ftypo3/typo3/sysext/core/Classes/Error/ErrorHandler.php on line 101
Fatal error: CLICmap\Clicmap\Controller\MapController::listAction(): Failed opening required '/var/www/html/ftypo3-fluid/typo3conf/ext/clicmap/Ressources/Private/PHP/GoogleMapAPIv3.class.php' (include_path='/var/www/html/ftypo3-fluid/typo3/contrib/pear/:.:/usr/share/php:/usr/share/pear') in /var/www/html/ftypo3/typo3conf/ext/clicmap/Classes/Controller/MapController.php on line 52
EDIT : Solved
The code that solved my problem in the controller :
require_once(PATH_site . 'typo3conf/ext/clicmap/Resources/Private/PHP/GoogleMapAPIv3.class.php');//OK
$gmap = new \GoogleMapAPI();
I was messing with the filepath and most importantly i hadn't put a \ before my class instanciation.
The code that solved my problem in the controller :
require_once(PATH_site . 'typo3conf/ext/clicmap/Resources/Private/PHP/GoogleMapAPIv3.class.php');//OK
$gmap = new \GoogleMapAPI();
I was messing with the filepath and most importantly i hadn't put a \ before my class instanciation.

Invalid controller using custom routes

I've been following the instruction on how to create custom routes from the book Zend Framework - A Beginners Guide
I've changed my application.ini file to include this routing information:
resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.view = static-content
resources.router.routes.static-content.defaults.action = display
Given the above configuration, I have this controller:
<?php
class Default_StaticContentController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function displayAction()
{
// action body
$page = $this->getRequest()->getParam('page');
if (file_exists($this->view->getScriptPath(null) .
'/' . $this->getRequest()->getControllerName() . '/' .
$page . $this->viewSuffix
)) {
$this->render($page);
}
else {
throw new Zend_Controller_Action_Exception('HLC - Page not found', 404);
}
}
}
I have a view named about.phtml in the APPLICATION_PATH/modules/default/views/static-content folder.
What ahppens is I get an error saying:
An error occurred
Page not found
Exception information:
Message: Invalid controller class ("StaticContentController")
Stack trace:
#0 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Dispatcher/Standard.php(262): Zend_Controller_Dispatcher_Standard->loadClass('StaticContentCo...')
#1 /Applications/MAMP/htdocs/zend/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#2 /Applications/MAMP/htdocs/zend/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#3 /Applications/MAMP/htdocs/zend/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#4 /Applications/MAMP/htdocs/HLC/public/index.php(26): Zend_Application->run()
#5 {main}
Request Parameters:
array (
'page' => 'about',
'module' => 'default',
'controller' => 'static-content',
'view' => 'static-content',
'action' => 'display',
)
Note that it is not rendering my customised Zend_Controller_Action_Exception but throwing the global error.
I'm using the URL: http://hlc.local:8888/content/about
The default index action works ok, just this routing that's not working.
if you are actually following the book closely, you have an extra line in your route declaration and your controller class should be StaticContentController.
here is the route definition from the book that does work.
resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.action = display
I still have this code laying around from last summer.
I found this book less then satisfactory and not really for beginners. It fails to address the Zend_Db component opting instead to introduce Doctrine 1.2. It's seems to be a trend that a number of these beginner/easy books feel that a full ORM is more useful then Zend_Db. If you are already familiar with Doctrine this approach works fine, otherwise it's a lot to ask of a beginner, to learn ZF and Doctrine at the same time.
Hope this helps.
I don't now what you use for autoloading. so that would helpful to determine.so far I understand your class named should be something like this ModulePath_ApplicationPath_ControllerName, so its Default_Application_StaticContentController.
and for better routing I preferred zend manual. you can try this tutorial for route. it would help for you.

Zend Mail keeps giving me a Socket Error

I'm having trouble with sending email using the zend framework. I keep getting a "Could not open socket" error.
I don't know whats wrong here - it used to work on my other host. Ever since I shifted it to another host I can't send emails. I've set up the configuration values to match the new email server.
Heres my code:
$config = array('auth' => _config('mail', 'auth'),
'username' => _config('mail', 'email'),
'password' => _config('mail', 'password'));
$tr = new Zend_Mail_Transport_Smtp(_config('mail', 'smtp'), $config);
$mail = new Zend_Mail();
$mail->setDefaultTransport($tr);
$mail->setFrom(_config('mail','email'), _config('mail','name'));
$mail->addTo($account_email);
$mail->setSubject($mailTitle);
$mail->setBodyText($mailContent);
$mail->send($tr);
EDIt ===
Well the code posted above is my actual code - I don't know whats wrong with it as it used to work on another host.
The following is the exact error I'm getting
Could not open socketstring(1237) "#0 /home/india/public_html/demo/library/Zend/Mail/Protocol/Smtp.php(167): Zend_Mail_Protocol_Abstract->_connect('tcp://mail.indi...')
#1 /home/india/public_html/demo/library/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp->connect()
#2 /home/india/public_html/demo/library/Zend/Mail/Transport/Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#3 /home/india/public_html/demo/library/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#4 /home/india/public_html/demo/application/controllers/AccountController.php(2153): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp))
#5 /home/india/public_html/demo/library/Zend/Controller/Action.php(513): AccountController->forgetPasswordAction()
#6 /home/india/public_html/demo/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('forgetPasswordA...')
#7 /home/india/public_html/demo/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /home/india/public_html/demo/application/bootstrap.php(26): Zend_Controller_Front->dispatch() #9 /home/india/public_html/demo/html/index.php(4): Bootstrap::run() #10 {main}"
marhaba Ali! ,
digging the code of Zend mail shows http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Mail/Protocol/Abstract.php
protected function _connect($remote)
{
$errorNum = 0;
$errorStr = '';
// open connection
$this->_socket = #stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
if ($this->_socket === false) {
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception($errorStr);
}
if (($result = $this->_setStreamTimeout(self::TIMEOUT_CONNECTION)) === false) {
/**
* #see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('Could not set stream timeout');
}
return $result;
}
and usually the error number 0 because of
if ($errorNum == 0) {
$errorStr = 'Could not open socket';
}
from : http://php.net/manual/en/function.stream-socket-client.php
On failure the errno and errstr
arguments will be populated with the
actual system level error that
occurred in the system-level connect()
call. If the value returned in errno
is 0 and the function returned FALSE,
it is an indication that the error
occurred before the connect() call.
This is most likely due to a problem
initializing the socket. Note that the
errno and errstr arguments will always
be passed by reference.
I guess its some firewall blocking the connection to be sent out ,
system-level or network-level error
If you update your answer with more detailed info , i would be happy to help

Zend Framework : Invalid contrller specified (error) ??? Help

I moved my project from windows to ubuntu and had this error while trying to run the project:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with
message 'Invalid controller specified (error)' in
/home/truong/webdev/qtcmsv2/library/Zend/Controller/Dispatcher/Standard.php:248
Stack trace:
#0 /home/truong/webdev/qtcmsv2/library/Zend/Controller/Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
#1 /home/truong/webdev/qtcmsv2/library/Zend/Application/Bootstrap/Bootstrap.php(97):
Zend_Controller_Front->dispatch()
#2 /home/truong/webdev/qtcmsv2/library/Zend/Application.php(366):
Zend_Application_Bootstrap_Bootstrap->run()
#3 /home/truong/webdev/qtcmsv2/index.php(56):
Zend_Application->run()
#4 {main} thrown in
/home/truong/webdev/qtcmsv2/library/Zend/Controller/Dispatcher/Standard.php
on line 248
I did have ErrorController.php file in my default module :
class ErrorController extends Zend_Controller_Action {
/**
* This action handles
* - Application errors
* - Errors in the controller chain arising from missing
* controller classes and/or action methods
*/
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 error -- controller or action not found
$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
$this->view->title = 'HTTP/1.1 404 Not Found';
break;
default:
// application error; display error page, but don't change
// status code
$this->view->title = 'Application Error';
break;
}
$this->view->message = $errors->exception;
}
}
My project ran very smoothly in Windows, but the error above always occurs when running in Ubuntu.
How can I solve this problem?? Please help me!
ps : Sorry for my bad English.
Means ZF can't find the error controller so it could be that something is not where it belongs, something is configured incorrectly (like a path), is misnamed, permissions are off, etc. Hard to tell from the info you provided as the error could be in index.php, your bootstrap, config, etc.