Error in in my first zend app - zend-framework

hello all its my first application using Zend Framework i have followed tutorial it was very nice and simple after finishing i got the following error .anyone please tell me why i am getting this ??
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in C:\xampp\htdocs\zend_login\library\Zend\Controller\Dispatcher\Standard.php:248
Stack trace:
#0 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch()
#2 C:\xampp\htdocs\zend_login\web_root\index.php(9): Zend_Controller_Front::run('/application/co...')
#3 {main}
Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)
#0 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\xampp\htdocs\zend_login\library\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch()
#2 C:\xampp\htdocs\ in C:\xampp\htdocs\zend_login\library\Zend\Controller\Plugin\Broker.php on line 336
this is my index.php in web_root folder
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
date_default_timezone_set('Europe/London');
$rootDir = dirname(dirname(__FILE__));
set_include_path($rootDir . '/library' . PATH_SEPARATOR . get_include_path());
$rootDir . '/library' . PATH_SEPARATOR . get_include_path();
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run('/application/controllers');
?>

You have configured the error handler of Zend but there is no error handler controller. Your real problem should lie behind this.
Create a file ErrorController.php inside of your controllers directory with the following contents:
class ErrorController extends Zend_Controller_Action
{
/**
* Handles system errors and 404s
*/
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
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()->setHttpResponseCode(404);
$priority = Zend_Log::NOTICE;
$this->view->message = 'Page not found';
break;
default:
// application error
$this->getResponse()->setHttpResponseCode(500);
$priority = Zend_Log::CRIT;
$this->view->message = 'Application error';
break;
}
// Log exception, if logger available
if ($log = $this->getLog()) {
$log->log($this->view->message, $priority, $errors->exception);
$log->log('Request Parameters', $priority, $errors->request->getParams());
}
// conditionally display exceptions
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
$this->view->request = $errors->request;
}
/**
* Get the log
*
* #return Zend_Log|false
*/
public function getLog()
{
$bootstrap = $this->getInvokeArg('bootstrap');
if (!$bootstrap->hasResource('Log')) {
return false;
}
$log = $bootstrap->getResource('Log');
return $log;
}
}
And the corresponding view views/error/error.phtml:
<h2><?php echo $this->message ?></h2>
<?php if (isset($this->exception)): ?>
<h3>Exception information:</h3>
<p>
<b>Message:</b> <?php echo $this->exception->getMessage() ?>
</p>
<h3>Stack trace:</h3>
<pre><?php echo $this->exception->getTraceAsString() ?></pre>
<h3>Request Parameters:</h3>
<pre><?php echo $this->escape(var_export($this->request->getParams(), true)) ?></pre>
This are more or less the defaults the Zend Framework scripts create on creation of a new project (They are modified a little since I do not have a clean version at the moment and no time to create a new project - But it should work.)
You may read more on the error handler here: http://framework.zend.com/manual/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler

Related

zend $acl->has() recource bt $acl->isAllowed returning false

I am facing a strange problem with zend_acl, I have successfully added role and resources , but the isAllowed() function is always redirecting to the error controller.
$usersNs->role = 'admin';
$acl->addRole(new Zend_Acl_Role($usersNs->role));
$acl->add(new Zend_Acl_Resource("dashboard::stats"));
$privilageName = $request->getControllerName()."::".$request->getActionName();
if($acl->has($privilageName)){
echo "has privelage"; //echo every time whenever i go to dashboard,stats
}
if(!$acl->isAllowed($usersNs->role,$privilageName )) {
$request->setControllerName('error');
$request->setActionName('error');
}

Zend_Navigation init in Bootstrap

Zend Framework v1.12
Tryed to init navigation in bootstrap and everything is fine, except appending it to view.
Here is a code snippet:
protected function _initNavigation() {
$this->bootstrap('view');
$view = $this->getResource('view');
include_once 'views/navigation.php';
$nav = new Zend_Navigation($navigation);
$view->navigation($nav);
}
Error occures because of last line. Stacktrace:
Uncaught exception 'Zend_Controller_Router_Exception' with message 'Route archive is not defined' in C:\OpenServer\domains\zend.vortexed\library\Zend\Controller\Router\Rewrite.php:318
Stack trace: #0 C:\OpenServer\domains\zend.vortexed\library\Zend\Navigation\Page\Mvc.php(176): Zend_Controller_Router_Rewrite->getRoute('archive') #1
C:\OpenServer\domains\zend.vortexed\library\Zend\View\Helper\Navigation\HelperAbstract.php(686): Zend_Navigation_Page_Mvc->isActive(false) #2
C:\OpenServer\domains\zend.vortexed\library\Zend\View\Helper\Navigation\Menu.php(740): Zend_View_Helper_Navigation_HelperAbstract->findActive(Object(Zend_Navigation), 0, NULL) #3
C:\OpenServer\domains\zend.vortexed\library\Zend\View\Helper\Navigation\Menu.php(940): Zend_View_Helper_Navigation_Menu->_renderMenu(Object(Zend_Navigation), 'navigation', '', ' ', 0, NULL, false, false, NULL, false, 'active', 'menu-parent', false) #4
C:\OpenServer\domains\zend.vortexed\library\Zend\View\Helper\Navigation\Menu.php(1096): Zend_View_Helper_Navigation_Menu->renderMenu(NULL)
...
Dumping $nav shows that it is good.
Also i tryed such variant:
protected function _initNavigation() {
$this->bootstrap('layout');
$layout= $this->getResource('layout');
$view= $layout->getView();
include_once 'views/navigation.php';
$nav = new Zend_Navigation($navigation);
$view->navigation($nav);
}
...same error
There are different reasons for that error,
Some of them are given in the following answer,
you can find it in here ROUTER EXCEPTION.
posting link as the answer, which helped The OP to get his answer, for the sake of marking the question as it has served it's purpose..
This is not a view or layout error.
The exception tell you that the route 'archive' is not define.
Start by creating the 'archive' route.

Zend Acl - 'Resource 'error' not found

When I call the "users" controller, it is giving me this error:
**Fatal error:** Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'error' not found' in /home/zerego/library/Zend/Acl.php:364
Stack trace:
#0 /home/zerego/library/Zend/Acl.php(774): Zend_Acl->get('error')
#1 /home/zerego/application/plugins/AccessCheck.php(25): Zend_Acl->isAllowed('normal', 'error', 'error')
#2 /home/zerego/library/Zend/Controller/Plugin/Broker.php(309): My_Plugin_AccessCheck->preDispatch(Object(Zend_Controller_Request_Http))
#3 /home/zerego/library/Zend/Controller/Front.php(941): Zend_Controller_Plugin_Broker->preDispatch(Object(Zend_Controller_Request_Http))
#4 /home/zerego/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#5 /home/zerego/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#6 /home/zerego/public_html/index.php(26): Zend_Application->run()
#7 {main} thrown in /home/zerego/library/Zend/Acl.php on line 364
My acl document works fine with the other controllers, and is like this:
<?php
$acl = new Zend_Acl();
$roles = array('admin', 'normal');
// Controller script names. You have to add all of them if credential check
// is global to your application.
$controllers = array('error', 'auth', 'index', 'paginator', 'albums', 'users');
foreach ($roles as $role) {
$acl->addRole(new Zend_Acl_Role($role));
}
foreach ($controllers as $controller) {
$acl->add(new Zend_Acl_Resource($controller));
}
// Here comes credential definiton for admin user.
$acl->allow('admin'); // Has access to everything.
// Here comes credential definition for normal user.
$acl->allow('normal'); // Has access to everything...
$acl->deny('normal', 'albums'); // ... except the admin controller.
// Finally I store whole ACL definition to registry for use
// in AuthPlugin plugin.
$registry = Zend_Registry::getInstance();
$registry->set('acl', $acl);
?>
I found the answer !
I was working in the wrong Acl file. In the right Acl file i didn't add the "error" ou "users" resources.
Thanks for the help anyway. :)

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.