Zend Framework Create Custom View Helper? - php

I have tried multiple fixes but none have worked. I am getting this error:
Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception'
with message 'Plugin by name 'AddCss' was not found in the registry;
used paths: Zend_View_Helper_:
Zend/View/Helper/:/Users/cgunnels/dev/git/rove-git/application/views/helpers/'
in
/usr/local/zend/share/ZendFramework/library/Zend/Loader/PluginLoader.php:412
Stack trace: #0
/usr/local/zend/share/ZendFramework/library/Zend/View/Abstract.php(1182):
Zend_Loader_PluginLoader->load('AddCss') #1
/usr/local/zend/share/ZendFramework/library/Zend/View/Abstract.php(618):
Zend_View_Abstract->_getPlugin('helper', 'addCss') #2
/usr/local/zend/share/ZendFramework/library/Zend/View/Abstract.php(344):
Zend_View_Abstract->getHelper('addCss') #3
/Users/cgunnels/dev/git/rove-git/application/layouts/scripts/layout.phtml(6):
Zend_View_Abstract->__call('addCss', Array) #4
/Users/cgunnels/dev/git/rove-git/application/layouts/scripts/layout.phtml(6):
Zend_View->addCss(Array) #5
/usr/local/zend/share/ZendFramework/library/Zend/View.php(108):
include('/Users/cgunnels...') #6 /usr in
/usr/local/zend/share/ZendFramework/library/Zend/Controller/Plugin/Broker.php
on line 336
this is my class:
class Zend_View_Helper_Css extends Zend_View_Helper_Abstract {
public function css() {
die("test");
}
}
I followed the instructions on this page http://framework.zend.com/manual/en/zend.view.helpers.html and it doesn't work.
I also added this to my application.ini:
resources.view.helperPath = APPLICATION_PATH "/views/helpers"
Please help me out, thanks

answer provided by author:
I fixed it. So the filename was CssHelper.php I changed it to Css.php
and it worked. – chris gunnels

Related

How to add custom function ot User.php in MediaWiki?

I added the following custom function to User.php:
public function isUpgraded() {
return true;
}
and the following in my Foreground.skin.php which is my skin/theme for the wiki to simply access the value that the function returns:
$isUpgraded= $wgUser->isUpgraded();
but I get the following exception:
Fatal error: Uncaught Error: Call to undefined method User::isUpgraded() in /home/siteX/public_html/siteX.com/wiki/skins/foreground/Foreground.skin.php:106 Stack trace: #0 /home/siteX/public_html/siteX.com/wiki/includes/skins/SkinTemplate.php(251): foregroundTemplate->execute() #1 /home/siteX/public_html/siteX.com/wiki/includes/OutputPage.php(2388): SkinTemplate->outputPage() #2 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionRenderer.php(135): OutputPage->output() #3 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionRenderer.php(54): MWExceptionRenderer::reportHTML(Object(Error)) #4 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionHandler.php(75): MWExceptionRenderer::output(Object(Error), 2) #5 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionHandler.php(149): MWExceptionHandler::report(Object(Error)) #6 /home/siteX/public_html/dev. in /home/siteX/public_html/siteX.com/wiki/skins/foreground/Foreground.skin.php on line 106
Do I need to register the custom function in some other file in order for it to work? It might be worth mentioning that the code worked in MediaWiki 1.23 but I recently updated to 1.31 and can't get the following piece of code to work.

"Twig_Error_Loader Unable to find template", due to slashes added to template name

After upgrading macOS server, Twig seems to have broken. For some reason, the function normalizeName($name) in lib/Twig/Loader/Filesystem.php is breaking, and returning the template name with a slash before every character. For example, "index.html" becomes "/i/n/d/e/x/./h/t/m/l".
So when I try and use Twig's render() function that calls normalizeName(), I get the following error:
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'Unable to find template "/l/o/g/i/n/./h/t/m/l/" (looked into: /Library/Server/Web/Data/Sites/templates).'
Modifying normalizeName() so it simply returns what it was passed results in PHP terminating the script due to memory exhaustion (at about 125MB) in lib/Twig/Lexer.php on line 107.
The code with the problem is below.
require_once '/Library/Server/Web/Data/Sites/Twig/lib/Twig/autoloader.php';
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('/Library/Server/Web/Data/Sites/templates/');
$twig = new Twig_Environment($loader, array(
'cache' => '/Library/Server/Web/Data/Sites/cache/',
'auto_reload' => 1
));
$twig -> render('login.html');
The full stack trace:
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'Unable to find template "/l/o/g/i/n/./h/t/m/l/" (looked into: /Library/Server/Web/Data/Sites/sccs_templates).' in /Library/Server/Web/Data/Sites/Twig/lib/Twig/Loader/Filesystem.php:247
Stack trace:
#0/Library/Server/Web/Data/Sites/Twig/lib/Twig/Loader/Filesystem.php(159): Twig_Loader_Filesystem->findTemplate('login.html')
#1 /Library/Server/Web/Data/Sites/Twig/lib/Twig/Environment.php(329): Twig_Loader_Filesystem->getCacheKey('login.html')
#2 /Library/Server/Web/Data/Sites/Twig/lib/Twig/Environment.php(418): Twig_Environment->getTemplateClass('login.html', NULL)
#3 /Library/Server/Web/Data/Sites/Twig/lib/Twig/Environment.php(362): Twig_Environment->loadTemplate('login.html')
#4 /Library/Server/Web/Data/Sites/sccs_includes/setup.php(252): Twig_Environment->render('login.html', Array)
#5 /Library/Server/Web/Data/Sites/Default/sccs/index.php(3): require_once('/Library/Server...')
#6 {main} thrown in /Library/Server/Web/Data/Sites/Twig/lib/Twig/Loader/Filesystem.php on line 247
I'm running Yosemite with Apache 2.4.23 and PHP 5.5.36, Twig 1.28.2.
Many thanks for any help!

Zf2 "The iterator class does not exist" on Session\Container definition

Sometimes on my website (ZendFramework2), I get an error when setting a session variable.
The error:
PHP Fatal error: Uncaught exception 'Zend\\Stdlib\\Exception\\InvalidArgumentException' with message 'The iterator class does not exist' in /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php:374
Stack trace:
#0 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php(414): Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->setIteratorClass(NULL)
#1 [internal function]: Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->unserialize('a:4:{s:7:"stora...')
#2 /MySite/vendor/zendframework/zendframework/library/Zend/Session/SessionManager.php(95): session_start()
#3 /MySite/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\\Session\\SessionManager->start()
#4 /MySite/module/Application/Module.php(97): Zend\\Session\\AbstractContainer->__construct('site')
#5 [internal function]: Application\\Module->onBootstrap(Object(Zend\\Mvc\\MvcEvent))
#6 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php on line 374
Code Module.php line 97 :
$s_site = new \Zend\Session\Container('site');
I try but I can not find why. Do you have any idea? Need more informations?
Thank you.
The is a result of the setIteratorClass method in ArrayObject/PhpReferenceCompatibility being passed a null $class argument. I'm not sure why it sometimes gets a null, but the way I fixed it in my case was to set the iterator class as 'ArrayIterator' when passed a null object, like this:
if (!isset($class)) {
$class = 'ArrayIterator';
}
In the latest zf2 version, the ArrayObject/PhpReferenceCompatibility class has been removed, so please make the change in stdlib/ArrayObject.php.

Invalid controller specified (error) when trying Propel Query

I've added the Propel ORM to my Zend Framework project.
The following files are under my /application/configs folder:
application.ini
build.properties
classmap-gentsefeesten-conf.php
gentsefeesten-conf.php
runtime-conf.xml
schema.xml
Under /application/models I have:
gentsefeesten
map
om
query's
I work with modules so I have a modules folder with two folders in it (my modules).
In my "index.php" file I've added the following: (third rule)
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/models'),//propel
get_include_path(),
)));
So the application gets my models in my models folder.
But I always get the following error :
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in /Applications/MAMP/htdocs/GentseFeesten/library/Zend/Controller/Dispatcher/Standard.php:248
Stack trace:
#0 /Applications/MAMP/htdocs/GentseFeesten/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /Applications/MAMP/htdocs/GentseFeesten/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#2 /Applications/MAMP/htdocs/GentseFeesten/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#3 /Applications/MAMP/htdocs/GentseFeesten/public/index.php(27): Zend_Application->run()
#4 {main} Next exception 'Zend_Controller_Exception' with message 'Invalid controller specified (error)
#0 /Applications/MAMP/htdocs/GentseFeesten/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Re in /Applications/MAMP/htdocs/GentseFeesten/library/Zend/Controller/Plugin/Broker.php on line 336
It seems that you don't have access to the problem, because exceptions are catched by Zend_Controller_Plugin_ErrorHandler.
You have this exception because you have no ErrorController, and the handler is trying to call it.
You may have the exception details in your error logs.
In order to watch the error message., you can put this code in your bootstrap :
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions( false );
or in the application.ini :
resources.frontController.throwexceptions = false
(very useful in developpement configuration)
However, if you use the errorHanlder, you should implement an ErrorController

Uncaught exception 'Zend_Acl_Exception' with message 'Resource not found'

I am new to Zend Framework and I am trying to build a small website using it. So to build CMS I found one source code that is on Apress website of author Forrest Lyman. I also got the book from local market.
I wanted to have admin module separately so I have created admin module but I got problem in that I am not able to access controller other than IndexController. When I try to access other controller in admin module I am getting this error:
Fatal error: Uncaught exception 'Zend_Acl_Exception' with message 'Resource 'category' not found' in C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Acl.php:365 Stack trace: #0 C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Acl.php(846): Zend_Acl->get('category') #1 C:\Server\Zend\Apache2\htdocs\cms\library\CMS\Controller\Plugin\Acl.php(52): Zend_Acl->isAllowed('administrator', 'category', 'index') #2 C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Plugin\Broker.php(309): CMS_Controller_Plugin_Acl->preDispatch(Object(Zend_Controller_Request_Http)) #3 C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(941): Zend_Controller_Plugin_Broker->preDispatch(Object(Zend_Controller_Request_Http)) #4 C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() #5 C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #6 in C:\Server\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Plugin\Broker.php on line 312
I found the solution..
After making a controller, I have to add resources in Acl.php file which is located in (library/CMS/Controller/Plugin/).
Just add this in add resources section
$acl->add(new Zend_Acl_Resource('category'));
Then you can access it.
Thanks.

Categories