I've setup my application with Zend_Application. I have an _initAutoload() method in my Bootstrap.php wich looks like this:
public function _initAutoload(){
$this->bootstrap("frontController");
$front = $this->frontController;
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Client_');
$autoloader->registerNamespace('Frontend_');
$autoloader->registerNamespace('Global_');
$autoloader->registerNamespace('Global_Helper_');
$autoloader->setFallbackAutoloader(true);
$modules = $front->getControllerDirectory();
$default = $front->getDefaultModule();
foreach (array_keys($modules) as $module) {
if ($module === $default) {
continue;
}
$autoloader->pushAutoloader(new Zend_Application_Module_Autoloader(array(
"namespace" => ucwords($module),
"basePath" => $front->getModuleDirectory($module),
)));
}
return $autoloader;
}
I have setup FrontController to prefix the default module also (seems more logical to me) $front->setParam("prefixDefaultModule", true)
I think I have the usual directory structure.
The problem:
I've set up subdomains for every module that I have. Everything works fine in the main main domain (www). The main module is frontend. If frontend is the default module then stuff works :). Ok. Now. For every subdomain, I have the same index.php but theres changed the env value. For client subdomain the env value is client etc. Each env value corresponds to my application.xml section. Each application.xml subdomain section (client, api, etc) extend the main section which is called defaults (currently theres a testing section also which enables errors etc, so every subdomain extends testing and testing extends defaults).
Each subdomain section of the application.xml changes the default module name. So for section defaults its frontend, for section client its client, etc.
Now
When I access domain.com/client or domain.com/api - its fine. Both API & Client use Client_Model_NameOfTheModel and like it supposed to - it's located application/modules/client/models/NameOfTheModel.php and the DbTable/NameOfTheModel.php
WORKS
BUT
When I access the the module from its respective subdomain (client.domain.com, api.domain.com, etc) and the default module has been changed from frontend to its respective subdomain module name - it ends working. It even doesn't output that "stack trace".
Warning: include(Client/Model/ContactLists.php) [function.include]: failed to open stream: No such file or directory in [heres-my-path-to-root]/library/Zend/Loader.php on line 136
Warning: include() [function.include]: Failed opening 'Client/Model/ContactLists.php' for inclusion (include_path='[heres-my-path-to-root]/library:.:/usr/lib/php:/usr/local/lib/php') in [heres-my-path-to-root]/library/Zend/Loader.php on line 136
Fatal error: Class 'Client_Model_ContactLists' not found in [heres-my-path-to-root]/application/modules/client/controllers/ContactListsController.php on line 4
I've tried 2 days to get it working. It just doesn't. It just works under the default domain and doesn't when the application.xml changes its default module to its subdomain name. Like that. This point is very very crucial currently because I can't continue and this app needs to be out of sandbox (in early beta) by the end of this week.
Thanks for anyone for some advice.
PS. Sorry for the poor English. It isn't my native tongue
This is just a cursory guess, but it looks like it might be working on default because of these lines:
$autoloader->setFallbackAutoloader(true);
$modules = $front->getControllerDirectory();
$default = $front->getDefaultModule();
foreach (array_keys($modules) as $module) {
if ($module === $default) {
continue;
}
Essentially, if your module is the default module it skips it, which means it falls back to the fallback autoloader i would assume, and if the default autoloader cant find your models, well theres the issue. Is the concat of the root path in the error and the path of the class its trying to load correct?
Also, this looks like it might be wrong
"namespace" => ucwords($module),
I would think it would need to be
"namespace" => ucwords($module) . "_",
Like your other namespaces.
Which version of ZF are you using?
Are you using a later 1.8 - 1.10 version?
If so, you should be using the resource in Zend_Application for a module. It sets up autoloading for forms, models, helpers, etc under your modules.
If you are using an application.ini you should have a line like this for each module :
resources.modules.module_name = "enabled"
http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.modules
Related
My website is with a hosting provider that has the MessageFormatter class available on the server (Linux, PHP 7.0.27) but it is an old ICU version (4.2.1) that doesn't support my message {number,plural,=0{# available} =1{# available} other{# available}} and gives the error:
Message pattern is invalid: Constructor failed
msgfmt_create: message formatter creation failed: U_ILLEGAL_CHARACTER
...because of the =1 and =2 notation.
I'm not able to make changes to the server so how can I force using the fallback method provided by Yii2 which works just fine?
There is this hacky way you can try.
Copy the yii\i18n\MessageFormatter code to a new file. Name it MessageFormatter.php and place somewhere in your application (but not in vendor folder).
In this new file change the format() method to:
public function format($pattern, $params, $language)
{
$this->_errorCode = 0;
$this->_errorMessage = '';
if ($params === []) {
return $pattern;
}
return $this->fallbackFormat($pattern, $params, $language);
}
Don't change anything else (including namespace).
Now let's use Yii mapping.
Find a place in your application when you can put code that will be run every time in bootstrapping phase. Good place for this is common/config/bootstrap.php if you are using "Advanced Template"-like project.
Add there this line:
Yii::$classMap['yii\i18n\MessageFormatter'] = 'path/to/your/MessageFormatter.php';
Obviously change the path to the one you've chosen. Now Yii autoloader will load this class from your file instead of the original Yii vendor folder (as mentioned in Class Autoloading section of the Guide).
In the modified file MessageFormatter method presence of intl library is never checked so fallback is used as default.
The downside of this trick is that you need to update manually your file every time original Yii file is changed (so almost every time you upgrade Yii version).
Another approach is to configure I18N component in your application to use your custom MessageFormatter where you can extend the original file and just override format() method inside without modifying class map.
I have a Joomla website where I have a custom module with mod_myModuleName.php and mod_myModuleName.xml files and a folder where there are several PHP scripts that add special functionality to my module. There is a config.php file in the folder that holds an associative array with variables and their values hard-coded. The module works just fine.
What I want though is to provide administrator area for the values of the variables in the array, so that I can put values in administrator panel and get their values in config.php. In my mod_myModuleName.php I use <?php echo $params->get('param')?> and it works like a charm.
But when I try to use the same technique in the config.php it breaks my code. I tried to get the values in mod_myModuleName.php and then include it in config.php and use the variables but it does not work either. I have not got so much experience in php and cannot understand what can be the reason.
It sometimes gives me an error of something non object and I guess it must be something connected with object oriented php, am I right? And if so is there a way to overcome this without object orientation or how can I solve my problem?
The problem will be with the way you're using your config.php.
When your modules entry point file mod_myModuleName.php is loaded by Joomla the $params object is already available in that context, you need to provide it to your scripts.
If you look at something like the mod_articles_latest module you will notice that the helper class is included with this line:
require_once __DIR__ . '/helper.php';
And then helper class is has it's getList() method called statically with the $params passed into it, so that $params is available to class context:
$list = ModArticlesLatestHelper::getList($params);
Inside the helper class ModArticlesLatestHelper you will notice that the getList() expects the $params to be passed in.
public static function getList(&$params)
{
...
}
I would strongly recommend reading the articles in the Modules section of Developers Portal on the Joomla Doc's.
Try the "Creating a simple module" article.
I am using Code Igniter, The HMVC library, and Smarty with this library.
Smarty is working fine by default, however if I try to use smarty's inheritance feature ( {extends file="master.tpl"}) then we run into an issue.
The extends feature does not look in the module views folder for the extended file (in the above's case master.tpl), instead it only looks in the application/views/ folder and throws an error if it cannot find it.
I could add APPPATH."modules/smartytest/views" to the $config['template_directory'] array in the smarty config file. but that throws an error for each item in the array it checks first for the file. filemtime(): stat failed for application/views/master.tpl
and that has the added issue of, if I have three modules all the the array and the modules all have a master.tpl then no matter what module I call the extend from it will load the first one found.
So, is there a way to get smarty's extend function to behave nicely with the HMVC modules?
Ah, found a working solution,
in My_Parser.php edit the block at line 30 so it reads:
// Modular Separation / Modular Extensions has been detected
if (method_exists( $this->CI->router, 'fetch_module' ))
{
$this->_module = $this->CI->router->fetch_module();
//add the current module view folder as a template directory
if ($this->_module !== '')
$this->CI->smarty->addTemplateDir(APPPATH."modules/".$this->_module.'/views');
}
The one drawback of this method is that smarty will look in your application/views folder before the module views folder. if someone knows a solution to that then it would be fantastic.
The problem is that CI is not checking error_reporting() returns 0, because Smarty is using the # control operator:
So add the line at the top of the function "_exception_handler":
if (error_reporting() == 0) return;
To the "Common.php" file in the "_exception_handler" function (line 469), or create your own function with the same name before calling "CodeIgniter.php" in the index.php file.
Best!
I am having some problem with cache registry. Here, how I configured cache
resources.cache.frontEnd = core
resources.cache.backEnd = file
resources.cache.frontEndOptions.lifetime = 1200
resources.cache.frontEndOptions.automatic_serialization = true
resources.cache.backEndOptions.lifetime = 3600
resources.cache.backEndOptions.cache_dir = APPLICATION_PATH "/../cache"
After any page I load I am receiving following error message
Fatal error: Uncaught exception 'Zend_Application_Bootstrap_Exception'
with message 'Unable to resolve plugin "cache"; no corresponding
plugin with that name' in
C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application\Bootstrap\BootstrapAbstract.php:330
Stack trace: #0
C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application\Bootstrap\BootstrapAbstract.php(382):
Zend_Application_Bootstrap_BootstrapAbstract->getPluginResource('cache')
1 C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application\Bootstrap\BootstrapAbstract.php(394):
Zend_Application_Bootstrap_BootstrapAbstract->getPluginResources() #2
C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application\Bootstrap\BootstrapAbstract.php(625):
Zend_Application_Bootstrap_BootstrapAbstract->getPluginResourceNames()
3 C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application\Bootstrap\BootstrapAbstract.php(586):
Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #4
C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application.php(355):
Zend_Applicatio in
C:\Zend\Apache2\htdocs\hotelrwanda\library\Zend\Application\Bootstrap\BootstrapAbstract.php
on line 330
I am sure that this is configuration problem. Can anyone help me to solve this problem?
Try adding the following line to your config file, before your cache configuration :
pluginPaths.App_Application_Resource_ = App/Application/Resource
The error message means that Zend Framework cannot find a "cache" plugin.
It should be cachemanager not cache. Link to docs: http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.cachemanager
Error
The error means no "Cache.php" file can be found under the configured pluginPaths, either under the default directory "/library/Zend/Application/Resource" or the additional paths defined as pluginPaths in your configuration.
Solution
Most probably the pluginPaths in your configuration(application.ini) are not defined correctly or not at all.
So the plugin cannot be found.
I have several pluginPaths defined and when I tried to clone the zend app I had to redefine these locations and I made a mistake at one of them which resulted at this error.
Resource plugins
In Zend 1, resource plugins are classes and most are defined in application.ini with their parameters. They are initiated when required by the application.
The default resource plugin path is /library/Zend/Application/Resource, additional plugin paths can be defined using:
pluginPaths.Custom_Resource_Path = "path/to/Resource"
Custom classes can be added under "path/to/Resource":
// path/to/Resource/Custom.php:
class Path_To_Resource_Custom extends Zend_Application_Resource_ResourceAbstract
{
public function setParam1($param1) {
...
}
public function init()
{
...
}
In application.ini, the configuration is added:
resources.custom.param1 = '...';
resources.custom.param2 = '...';
Also
by creating a class with the same name as a default resource in the above directory, e.g. Log.php, the default resource can be overridden.
default resources can be changed, e.g. resources.view.encoding = "UTF-8"
I've never had problems with CakePHP's theming system in the past, but now, errors galore. My main issue is that all theme resources (those in /app/views/themed/MyTheme/webroot/*) fail to load. I've set up a custom AppController in /app to set the theme.
var $view = "Theme";
var $theme = "MyTheme";
When I go to any page, I can see that it's utilizing my theme's default.ctp layout and the HTML is fine. Any and all page resources, CSS, JavaScript, images, anything in the theme webroot, fails to load and instead gives me an error like the following (let's say I tried to access http://example.com/theme/MyTheme/img/bg.png):
Error: ThemeController could not be found.
Error: Create the class ThemeController below in file: app/controllers/theme_controller.php
<?php
class ThemeController extends AppController {
var $name = 'Theme';
}
I've never received an error like this in my time with CakePHP. I'm running the latest stable version at 1.3.7.
I've finally found a solution. CakePHP didn't like my uppercase theme name. In fact, any theme name that I tried that included uppercase characters failed to work. I changed my folder name and internal theme name from "MyTheme" to "my_theme" and it worked perfectly. Could possibly be a bug, but it could be undocumented, yet expected functionality.