how determine ZF2 the path to controller action phtml - zend-framework2

There is a controller: module/ModuleName/src/ModuleName/Controller/SubFolder/ControllerNameController
With action: doSomethingAction()
In module.config.php:
'view_manager' => [
'template_path_stack' => array(
'ModuleName' => __DIR__ . '/../view',
),
]
In one of my projects ZF2 search the .phtml file like this: view/module-name/sub-folder/controller-name/do-something.phtml
This is ok for me.
But in another project ZF2 search the .phtml file like this: view/module-name/controller-name/do-something.phtml
This is not ok for me, because the controller name must be unique in the module.
Where is the reason for this behavior?
Why does ZF2 ignore the folder?

This is probably due to the two different projects using different versions of ZF2. I would guess that the project where the sub-folder is included in the view template path is a version of ZF2 post 2.3.2 and the project where it is not included is a version pre 2.3.2.
You can take a look at the pull request here: https://github.com/zendframework/zendframework/pull/5670
If you are running a pre 2.3.2 application I would suggest you should update your ZF2 dependency to the latest stable release
There was also some breaking changes merged in this pull request which I believe are part of ZF3:
https://github.com/zendframework/zend-mvc/pull/139
Which could be of use if you are already using a later version of the framework

Thank you. It was the missing __NAMESPACE__ variable in the routes.

Related

How do I override package language files in Laravel 5.1

According to Laravel Docs: https://laravel.com/docs/5.1/localization#overriding-package-language-files
for example, if you need to override the English language lines in messages.php for a package named skyrim/hearthfire, you would place a language file at: resources/lang/vendor/hearthfire/en/messages.php.
I currently have the package activewebsite/enterprise-entity package that I am including in my project. It contains a language file:
vendor/activewebsite/enterprise-entity/src/resources/lang/en/phone.php
This file contains translations for types of phone numbers:
'phone_1' => 'Home',
'phone_2' => 'Work',
'phone_3' => 'Mobile',
'phone_4' => 'Office',
'phone_5' => 'Fax',
'phone_6' => 'Fax 2',
'phone_7' => 'Home 2',
'phone_8' => 'Direct',
Following the example above, I attempted to override this file by creating the following directory:
resources/lang/vendor/enterprise-entity/en/phone.php
containing an additional phone number specific to this project:
'phone_9' => 'Rapid Rewards Text Alert Number',
But the the translation does not come through to the front-end. The only way I've been able to get the translation to appear is to edit the language file within the enterprise-entity package.
I found this thread: https://octobercms.com/forum/post/localication-problems-where-to-overwrite-octobercms-lang-settings-in-general
Where another user seems to be having a similar issue, but it is suggested that they use the directory structure:
/lang/{locale}/{vendor}/{plugin}/lang.php
so I attempted
/lang/en/activewebsite/enterprise-entity/phone.php
with no luck.
Can anyone tell me what I may be getting wrong here? I've attempted running a php artisan optimize after each change to see if that could clear things up, but no luck.
Thanks!
Turns out the folder structure needs to use the NAMESPACE for the package, camelcase, not follow the same naming convention/directory structure as in the package or in the docs. So, for my example, the namespace used for the enterprise-entity package is EnterpriseEntity, camelcased would be enterpriseEntity.
The correct directory structure would be:
resources/lang/vendor/enterpriseEntity/en/phone.php
From Laravel Official Documentation
Overriding Package Language Files
Some packages may ship with their own language files. Instead of changing the package's core files to tweak these lines, you may override them by placing files in the resources/lang/vendor/{package}/{locale} directory.
So, for example, if you need to override the English translation strings in messages.php for a package named skyrim/hearthfire, you should place a language file at: resources/lang/vendor/hearthfire/en/messages.php. Within this file, you should only define the translation strings you wish to override. Any translation strings you don't override will still be loaded from the package's original language files.

ASP.NET MVC 4 bundle with wildcard in folder path

My team uses a custom NuGet package for installing jQuery UI, which puts the theme files into a directory structure like this:
Content
jquery-ui-1.10.3
images
jquery-ui.css
jquery-ui.min.css
I'm trying to use ASP.NET MVC 4 bundles to include this content in the BundleConfig class inside my application's App_Start folder like so:
bundles.Add( new StyleBundle( "~/bundles/css" )
.Include( "~/Content/normalize-{version}.css",
"~/Content/jquery-ui-{version}/jquery-ui.css",
"~/Content/Site.css" ) );
This throws an error when I run the site:
Directory does not exist.
Parameter name: directoryVirtualPath
I also tried:
bundles.Add( new StyleBundle( "~/bundles/css" )
.Include( "~/Content/normalize-{version}.css" )
.IncludeDirectory( "~/Content/jquery-ui-*", "*.css" )
.Include( "~/Content/Site.css" ) );
That doesn't work either (obviously). I can explicitly specify the version on the folder, but that defeats part of the benefit of using the bundle.
So how can I use a wildcard in the folder path?
You could use the overloaded version of IncludeDirectory which searches subdirectories.
Suppose you have the following file:
\Root\Content\jquery-ui-1.10.3\jquery-ui.css
Use this code to find and add it:
.IncludeDirectory("~/Content", "jquery-ui.css", true)
This is useful because it will always find jquery-ui.css, regardless of where you put it.
The downside to this method is that it will search for and include all jquery-ui.css files that it finds, which could cause some bugs if you don't ensure that only one jquery-ui.css exists.
(Remember that searching for subdirectories will also still search the root directory i.e. ~/Content)

ZF2 : How do i include the Zend_Acl component into my custom built php app?

I'm trying to use the Zend/Permissions/Acl/Acl class into my custom built php application but I cannot get past encountering this error :
Fatal error: Class 'Zend\Permissions\Acl\Acl' not found in /users/myuser/htdocs/test/index.php on line 9
Here is a screenshot of my file system organization and my php code I'm using.
I copied the Acl initialization code from the documentation here : http://framework.zend.com/manual/2.1/en/modules/zend.permissions.acl.intro.html
I'm new to Zend framework but would really like to start using the Acl class. Please help.
use is not a replacement for require, you will need an autoloader so that the files will be included. Have a look at the StandardAutoloader of ZF 2.
On a separate note: it's safer to use absolute paths in the include path:
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . __DIR__ . '/libraries');

Renaming namespace in ASP.NET MVC Project: compile OK, Running not OK

How to fix ?
Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'Home' has found the following matching controllers:
MyProject1.Controllers.HomeController
MyProject2.Controllers.HomeController
Probably need a little bit more details. For e.g. Did you change the namespace from MyProject1 to MyProject2?
Check your bin folder to see if any of dlls from the old namespace are still around. If that's the case cleaning them up and recompiling should fix the issue.
Make sure you edit the default namespace setting in your web project properties, on the Application tab.
I assume this is in your Views. Be certain the namespaces in your views is correct.

Mapping controller names to urls (with packages)

Is it possible to configure grails to resolve controllers and actions using the package they are in as sub-folders?
For example, say I have the following directory structure:
/grails-app/controllers/HomeController.groovy (with action index)
/grails-app/controllers/security/UserController.groovy (with actions index, edit)
/grails-app/controllers/security/RoleController.groovy (with action index, edit)
I would like grails to generate the following url mappings automatically:
http://localhost:8080/myApp/ => HomeController.index
http://localhost:8080/myApp/security/user/ => UserController.index
http://localhost:8080/myApp/security/user/edit => UserController.edit
http://localhost:8080/myApp/security/role/ => RoleController.index
http://localhost:8080/myApp/security/role/edit => RoleController.edit
I would be a bit wary of mapping them directly to your package names. Doing that will make it very hard for you to refactor in the future, especially once your application is out in the wild. It's also going against the conventional nature of Grails.
However, you can still manually structure your URLs to map to different paths. For your question, here's an example:
// grails-app/conf/UrlMappings.groovy
'/security/user/$action?/$id?' (controller: 'user')
'/security/role/$action?/$id?' (controller: 'role')
// the rest of the default UrlMappings are below
'/$controller/$action?/$id?' {}
Since controllers are typically referenced by name, e.g. "user" in your case, it's not easy to go against this convention; it'd be trying to fight the framework instead of letting it do the work for you.
It's probably possible to do this based on package (maybe using Reflection, or something?), but not advisable.
I believe you are looking for Grails URLMapping constraint. Look here: Grails - URL mapping

Resources