I have following directory structure for view helper in my zendframework project
--application
--views
--helpers
--Test.php
and configuration setting in application.ini is
resources.view.helperPath = APPLICATION_PATH "/views/helpers"
and configuration in Bootstrap.php is
$view->setHelperPath(APPLICATION_PATH . "/views/helpers/");
in Test.php file naming convention is
class Zend_View_Helper_Test extends Zend_View_Helper_Abstract {}
and I am using helper function in module wherever I need it.When I run project via browser, application working fine without any error, but when I invoke phpunit for same application via command line I am getting error something like
Fatal error: Uncaught exception 'ErrorException' with message 'include_once(Zend\View\Helper\Test.php): failed to open stream: No such file or directory' in D:\
zend\ZendServer\share\ZendFramework-1.12.11\library\Zend\Loader.php:134
that means it's going to find Test.php file in zend server library view folder.I am not getting why it's working via browser and not working in phpunit via command line.
I got solution. I have replace my configuration setting of application.ini
resources.view.helperPath = APPLICATION_PATH "/views/helpers"
with
resources.view.helperPath.Application_View_Helper = APPLICATION_PATH "/views/helpers/"
and changed naming convention of Test.php with
class Application_View_Helper_Test extends Zend_View_Helper_Abstract {}
now zend loder will try to find view helper in application directory rather than Zend
Related
The current Behavior:
I wanted to add an extra custom type and followed:
https://docs.typo3.org/p/georgringer/news/master/en-us/DeveloperManual/ExtendNews/AddCustomType/Index.html
Exactly at it was explained there...
The expected behavior/output:
This gives me in the Backend an extra custom type myCustomNewsType.
However, when I call the Frontend, I get:
Core: Exception handler (WEB): Uncaught TYPO3 Exception:
#1476045117: Could not find class definition for name "Galileocr\CustomPackage\Domain\Model\MyCustomNewsType".
This could be caused by a mis-spelling of the class name in the class definition. | TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException thrown in file /usr/home/galileo98/public_html/typo3_src-9.5.11/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php in line 131.
Environment
TYPO3 version(s): [9.5.0]
news version: [e.g. 7.0.5]
Composer (Composer Mode): [ no]
OS: [e.g. OSX 10.13.4]
I have no idea why this occurs, is this example not complete?
Did you configure the class autoloading after adding the new class? If this is a try-out, you should add an autoloading line to the composer.json in the root of your project.
{
"autoload": {
"psr-4": {
"Galileocr\\CustomPackage\\": "typo3conf/ext/custom_package/Classes/"
}
}
}
After that you should regenerate the autoload files by issuing a composer dumpautoload from the directory in which you just edited the composer.json.
I did not make the TYPO3 install with composer (no composer file in the root of my project), did it the "classical" way.
However, you definitely pointed me in the right direction: I opened the file typo3conf/autoload/autoload_psr4.php:
<?php
// autoload_classmap.php #generated by TYPO3
$typo3InstallDir = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/';
return array(
'BK2K\\BootstrapPackage\\' => array($typo3InstallDir . 'typo3conf/ext/bootstrap_package/Classes'),
'GeorgRinger\\News\\' => array($typo3InstallDir . 'typo3conf/ext/news/Classes'),
);
So no reference to my custom class...
Therefore, I went to Admin tools->Maintenance->Rebuild PHP Autoload Information and refreshed the autoload info. After that, the same file looks like this:
<?php
// autoload_classmap.php #generated by TYPO3
$typo3InstallDir = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/';
return array(
'BK2K\\BootstrapPackage\\' => array($typo3InstallDir . 'typo3conf/ext/bootstrap_package/Classes'),
'Galileocr\\BciePackage\\' => array($typo3InstallDir . 'typo3conf/ext/bcie_package/Classes'),
'GeorgRinger\\News\\' => array($typo3InstallDir . 'typo3conf/ext/news/Classes'),
);
The the problem was fixed!!!
Thanks and regards!
Bert
When trying to include the JPGRAPH library in a Zend Studio project, I got the error
Fatal error: Class 'Graph' not found in C:\Program Files\Zend\Apache2\htdocs\NewStokV4\application\controllers\StatsController.php on line 49
when executing my code.
I tried to follow, unsuccessfully, some tutorials on the net, but none were complete nor clear to me. (I'm new in Zend framework development.)
this is what i get when trying include... or require...
Warning: require_once(vendors/jpgraph-3.5.0b1/src/jpgraph.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files\Zend\Apache2\htdocs\NewStokV4\application\controllers\StatsController.php on line 15
Fatal error: require_once() [function.require]: Failed opening required 'vendors/jpgraph-3.5.0b1/src/jpgraph.php' (include_path='C:\Program Files\Zend \Apache2\htdocs\NewStokV4\vendors\Oft_Framework-G1R1C0/vendors/minify-2.1.5/min/lib;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\Oft_Framework-G1R1C0/vendors/htmlpurifier-4.4.0/library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\ZendFramework-1.10.7\library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\Oft_Framework-G1R1C0\library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4/library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\ZendFramework-1.10.7\extras\library') in C:\Program Files\Zend\Apache2\htdocs\NewStokV4\application\controllers\StatsController.php on line 15
Regarding your comment:
Solution A (a bit dirty)
Put the whole JPGRAPH library inside \library\jpgraph folder an include it inside your controller via:
require_once(APPLICATION_PATH . '/../library/jpgraph/jpgraph.php');
Solution B (better)
Check if jpgrah uses namespaces. if yes you might want try to load it with the build in autoloader function of zend. Put the whole JPGRAPH library inside \library\JPGraph folder.
Usage: just add autoloaderNamespaces[] = "<jpgraph_namespace>" to your application.ini where <jpgraph_namespace> is the namespace of jpgraph.
So assuming the namespace is JPGraph:
application.ini:
[...]
includePaths.library = APPLICATION_PATH "/../library"
[...]
autoloaderNamespaces[] = "JPGraph"
in your controller:
[...]
$JPGraph = new JPGraph();
[...]
I'm trying to get the zend framework running, but the include path doesn't like me ;)
The zend directory is here http://mydomain.com/zend/
<?php
set_include_path('/var/www/www.mydomain.com/htdocs/zend/library/');
require_once 'Zend/Gdata/Youtube.php';
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
?>
And I get this error:
Warning: require_once(Zend/Gdata/Youtube.php) [function.require-once]:
failed to open stream: No such file or directory in
/var/www/www.mydomain.com/htdocs/zend/index.php on line 4
Fatal error: require_once() [function.require]: Failed opening
required 'Zend/Gdata/Youtube.php'
(include_path='/var/www/www.mydomain.com/htdocs/zend/library/') in
/var/www/www.mydomain.com/htdocs/zend/index.php on line 4
I have a smiliar setup on another server where it works, but here has to be something wrong..
I think you want:
require_once 'Zend/Gdata/YouTube.php';
(note the capital T). Your other server where it works is probably using a case-insensitive file system.
I think I've tried everything I've found to solve this, including all the answers here on SO.
In my project there is an admin module, and then there's the default module. Now I want the admin module to use the default module's helpers. Preferably only if there isn't an admin module helper with the same name. Is this possible?
The error message I get is:
Message: Plugin by name 'HeadBase' was not found in the registry; used
paths: Admin_View_Helper_:
/application/modules/admin/views\helpers/
Zend_View_Helper_: Zend/View/Helper/
I use ZF 1.11
Found a solution. In the Bootstrap, add an init for helpers, like this:
protected function _initHelpers()
{
$this->bootstrap('view');
$view = $this->getResource('view');
$view->addHelperPath(APPLICATION_PATH . '/views/helpers/', 'Zend_View_Helper');
}
This adds the helper path APPLICATION_PATH . '/views/helpers/' for helpers whose class is prefixed with Zend_View_Helper.
I get the following error messages:
Warning: include_once(Zend\Db.php) [function.include-once]:
failed to open stream: No such file or directory in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83
Warning: include_once() [function.include]:
Failed opening 'Zend\Db.php' for inclusion (include_path='VPZ/') in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83
Warning: require_once(Zend/Exception.php)
[function.require-once]: failed to open stream:
No such file or directory in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 87
Fatal error: require_once() [function.require]:
Failed opening required 'Zend/Exception.php' (include_path='VPZ/') in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 87
i want to include ZendXXX\Db.php
how to change it
create a directory (say 'lib'), and put your Zend directory in it. so your directory structure looks like this:
- application
- lib
|- Zend
- wwwroot
|- index.php
now you should add lib to your include path. edit your index.php file:
$includePath = array();
$includePath[] = '.';
$includePath[] = './../application';
$includePath[] = './../lib';
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);
now you have your lib in your include path. you can include all Zend components like this:
include 'Zend/Loader.php';
require_once 'Zend/Db.php';
the best way is too include Zend_Loader first and then use it to load classes. do this:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Db');
you can also register to autoload classes. just add this line to your code after all those before:
Zend_Loader::registerAutoLoad('Zend_Loader',true);
now you do not need to include files to call classes. just instanciate your classes:
$session = new Zend_Session_Namespace('user');
there is no need to include 'Zend/Session/Namespace.php'.
Use set_include_path(). See PHP.net documentation
Example:
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');
I usually store the framework files under a "library" folder:
application
public_html
library
Zend
Common
etc....
and then in my bootstrap file, or front controller, I add that "library" folder to the include path:
set_include_path(get_include_path() . PATH_SEPARATOR . '../library');
See also:
Choosing Your Application's Directory Layout.
Create the Filesystem Layout.
The reason the other suggestions say anything about doing that, is because it's a bad move - in other words, you're doing it wrong.
You can create a subdirectory and name it Zendxxx, but then you have to add that to your include_path, and change it, whenever you put a newly named version up.
I'd hazard a guess, and say that you don't have a good way to test the website (so you want to lock it to a particular version of ZF), and further, that you aren't using revision control, so you want all the previous versions of code in the site-directory to be able to go back to, if you find a problem when you change the live-running code directly on the server.
project without library And including library from one location
project C:\xampp\htdocs\my\application
library C:\xampp\Zend\library
make changes in index.php
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR,
array(realpath(APPLICATION_PATH.'/../../../Zend/library'),get_include_path(),)));