zend form giving error when working with modules - zend-framework

I have started learning zend framework. I am using version 1.12. I am using modular approach. I have created one module called 'admin'. Following the my structure of the site
application/
(...other directories)
modules/
admin/
controllers/
IndexController.php
forms/
Login.php
views/
scripts/
(...view scripts)
Bootstrap.php
In this module I have created one form called 'login' using zf tool. whose class is created like this.
class Admin_Form_Login extends Zend_Form
{
public function init()
{
}
}
now the problem comes when I called this form in my admin module's index controller.
class Admin_IndexController extends Zend_Controller_Action {
public function indexAction()
{
$form = new Admin_Form_Login;
}
}
It gives me error like this.
Fatal error: Class 'Admin_Form_Login' not found in E:\xampp\htdocs\novo\application\modules\admin\controllers\IndexController.php on line 13.
I am not sure what I am doing wrong. anybody, please help me.

I think you can do th enext things:
1. Enable autoloading for module's models:
in application.ini:
resources.modules = []
resources.views = []
resources.frontController.moduleDirectory = APPLICATION_PATH . "/modules"
Create form in modules/admin/models/Form/Login.php and call class Admin_Model_Form_Login
Check your module bootstrap. It should be:
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap

Related

SuiteCRM v7.10.29 Custom API v4.1

I am creating a custom API for SuiteCRM. When I attempt to run the new API from {CRM Home}/custom/service/v4_1_custom I receive an 'HTTP ERROR 500'. There are not errors in the error_log file or the SuiteCRM.log file.
I have followed the method in the following two url's
https://fayebsg.com/2013/05/extending-the-sugarcrm-api-updating-dropdowns/
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Integration/Web_Services/Legacy_API/Extending_Web_Services/
registry.php
<?php
require_once('service/v4_1/registry.php');
class registry_v4_1_custom extends registry_v4_1
{
protected function registerFunction()
{
parent::registerFunction();
$this->serviceClass->registerFunction('test', array(), array());
}
}
SugarWebServicesImplv4_1_custom.php
<?php
if(!defined('sugarEntry'))define('sugarEntry', true);
require_once('service/v4_1/SugarWebServiceImplv4_1.php');
class SugarWebServiceImplv4_1_custom extends SugarWebServiceImplv4_1
{
/**
* #return string
*/
public function test()
{
LoggerManager::getLogger()->warn('SugerWebServiceImplv4_1_custom test()');
return ("Test Worked");
} // test
} // SugarWebServiceImplv4_1_custom
I found the answer to this issue.
In the file {SuiteCRM}/include/entryPoint.php there are many files that are included thru require_once. In this list of require_once files, there were 4 files that were set as require not require_once. These were classes and therefore could not be included a second time. I changed these to require_once and the HTTP Error 500 went away and the custom APIs started working.

How to fix error "Cannot dispatch middleware Application\Middleware\IndexMiddleware"?

I've set up a Zend Application as normal, except in my case the difference is that I set it up over an existing legacy web application.
I still want to call my existing legacy application over the ZF3 app. It was suggested I can do so using Middleware. I went over https://docs.zendframework.com/zend-mvc/middleware/ and set up my routing as described there.
However, when I run the application, I am greeted by this:
Cannot dispatch middleware Application\Middleware\IndexMiddleware
#0 zend-mvc\src\MiddlewareListener.php(146):
Zend\Mvc\Exception\InvalidMiddlewareException::fromMiddlewareName('Application\\Mid...')
Here is where the exception happens:
https://github.com/zendframework/zend-mvc/blob/release-3.1.0/src/MiddlewareListener.php#L146
Just to note:
$middlewareToBePiped; //'Application\Middleware\IndexMiddleware'
is_string($middlewareToBePiped); // true
$serviceLocator->has($middlewareToBePiped);//false
$middlewareToBePiped instanceof MiddlewareInterface; //false
is_callable($middlewareToBePiped);//false
My class is:
namespace Application\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Zend\Http\Response;
class IndexMiddleware implements MiddlewareInterface
{
public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
{}
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{}
}
I am thinking that my issue is that my IndexMiddleware class is not being found in ServiceLocator... (line 142 of linked API). How do I get it in there?
I put this into my application.config.php file:
'service_manager' => [
'invokables' => array(
'middleware' => IndexMiddleware::class
)
]
onto the next error it is.. (Last middleware executed did not return a response.)
but looks like it has executed)

Action based navigation in Zend Framework

i have navigation menu which is displayed to users based on certain action of the controller. here is what i am doing.
//in each controller-action where i want "action navigation menu"
public function indexAction()
{
$this->_helper->navigation()->renderActionNavigation();
}
public function newAction()
{
$this->_helper->navigation()->renderActionNavigation();
}
the navigation menu is displayed accordingly. here is my navigation.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<item-index>
<new-item>
<label>New Item</label>
<route>admin-item-new</route>
</new-item>
<delete-item>
<label>Delete Item</label>
<uri>#</uri>
</delete-item>
</item-index>
<item-new>
<publish-unpublish-item>
<label>Save & Close</label>
<uri>#</uri>
</publish-unpublish-item>
<delete-item>
<label>Save & New</label>
<uri>#</uri>
</delete-item>
</item-new>
</configdata>
the parent element of each navigation menu represents a naming convention in the above navigation.xml file for example
`<item-index>` represents item{controller}index{action}
`<item-new>` represents item{controller}new{action}
//and so on
here is the action helper. Navigation.php i am using
class Zend_Controller_Action_Helper_Navigation extends Zend_Controller_Action_Helper_Abstract
{
private $_view = null;
public function direct()
{
$this->_view = Zend_Layout::getMvcInstance()->getView();
$this->_view->placeholder('action-navigation');
return $this;
}
public function renderActionNavigation()
{
$config = new Zend_Config_Xml(
APPLICATION_PATH.'/configs/navigation.xml', strtolower(
$this->getRequest()->getControllerName().'-'.
$this->getRequest()->getActionName()
)
);
$container = new Zend_Navigation($config);
$this->_view->partial('partials/_action-navigation.phtml', array('container' => $container));
}
}
and finally _action-navigation.phtml
<?php $this->placeholder('action-navigation')->captureStart(); ?>
<div class="statsRow">
<div class="wrapper" >
<?php foreach($this->container as $page): ?>
<?php endforeach; ?>
</div>
</div>
<?php $this->placeholder('action-navigation')->captureEnd(); ?>
My directory structure is as follows
/application
/layouts
admin.phtml
default.phtml
/modules
/admin
/controllers
/helpers
/Navigation.php
IndexController.php
/views
/helpers
/scripts
/partials
_action-navigation.pthml
sidebar.phtml
/index
/item
the weird behavior i am experiencing is. in my Bootstrap.php file there is an empty _initView() method. my application works properly if this method exist. note that this method is empty. but when i remove it it gives me following error.
Application error
Exception information:
Message: script 'partials/_action-navigation.phtml' not found in path (./views/scripts/)
i am not able to understand this behavior by Zend Framework. how is action-navigation code related to _initView method in Bootstrap? what is happening and any fix for this or any suggestion for improvement of my code?
Update:
The problem lies with this line of code
$this->_view->partial('partials/_action-navigation.phtml', array('container' => $container));
You forgot to add the name of the admin module as second argument:
$this->_view->partial('partials/_action-navigation.phtml', 'admin', array('container' => $container));
I Suggest you use this clean and lightweight way, removing your dependence to inform actual module and mantaining your view script clean without captureStart and End (it's used ob_start... when u do captureStart-end)
$navigation = $this->view->navigation()->menu()->renderPartial($container, 'partials/_action-navigation.phtml');
// U can use placeholders `append` and `prepend` methods too, if u need more control in your placeholder content
$this->view->placeholder('action-navigation')->set($navigation);

Problem deploying Zend Framework website: doesn't find the classes

I'm trying to deploy a website made with the Zend Framework. The website is running fine on my local environment, I'm trying to deploy it on my VPS. But I'm running into some difficulties.
Now it says the following:
*Fatal error: Class 'Doctrine_Manager' not found in /is/htdocs/wpxxxxx/www/mensenenjij/application/Bootstrap.php on line 12*
It properly includes the Doctrine classes but it can't instantiate a new Doctrine_Manager. Anybody knows why?
Bootstrap.php:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctrine()
{
require_once 'Doctrine/Doctrine.php';
$this->getApplication()
->getAutoloader()
->pushAutoloader(array('Doctrine', 'autoload'), 'Doctrine');
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(
Doctrine::ATTR_MODEL_LOADING,
Doctrine::MODEL_LOADING_CONSERVATIVE
);
$config = $this->getOption('doctrine');
$conn = Doctrine_Manager::connection($config['dsn'], 'doctrine');
return $conn;
}
}

Zend framework ignores custom helper path in application.ini

I have my view helper in Library/My/View/Helper/LoadSkin.php, I added this line in application.ini : resources.view.helperPath.My_View_Helper = "My/View/Helper" but I'm still getting
Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message
'Plugin by name 'LoadSkin' was not found in the registry; used paths: Zend_View_Helper_: Zend/View
/Helper/;C:/Program Files (x86)/Zend/Apache2/htdocs/TinOuzel/application/views\helpers/'
This looks like ZF stills looks for helper in default path ;/
My namespacje is registered in bootstrap:
protected function _initAutoloader ()
{
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('My_');
$autoloader->suppressNotFoundWarnings(true);
return $autoloader;
}
in this case , you must had overridden the default view object
in much clear example , you are using something like :
$view = new Zend_View();
mostly somewhere in your bootstrap file , just remove it and you would be okay