ZF2 Modules in Subfolders - module

due to a large project which will be realised in ZF2, I came across the following problem and I seem to misunderstand the handling of namepaces.
The project will have a lot of modules of similar groups. I will have 4 groups (A, B, C, D) and all modules in group A will deal with input for example. In order to make sure, that we do not end up with a folder containing 200 modules, we want to group the ones that belong together for reasons of cleanliness.
So basically we wish for the following structure:
/config
/module
/MainApplication <- accesses all modules
/groupA
/Module1
/Module2
/groupB
/Module3
/Module4
...
I already adjusted the namespace to groupA\Module1, adjusted the routes accordingly and all the paths seem to be correct and yet I get errors saying that for example the template files cannot be accessed.
Can you give me a hint what you would have to pay attention to when you move a model from /modules/module1 to /modules/subfolder/module1.
What I tried
Changed all namespaces to: -------------------------------------------
groupa\module1[\Controller];
/config/application.php: ---------------------------------------------
...
'modules' => array(
'groupa\module1',
),
...
/module/groupa/Module.php: -------------------------------------------
...
'route' => '/',
'defaults' => array(
'controller' => 'groupa\module1\Controller\Index',
'action' => 'index',
),
...
'controllers' => array(
'invokables' => array(
'groupa\module1\Controller\Index' => 'groupa\module1\Controller\IndexController'
Currently, the module is not supposed to do much. Just showing the index.phtml template. The error I get is the following:
Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException' with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render template "groupa/index/index";
resolver could not resolve to a file' in /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/Renderer/PhpRenderer.php:461
Stack trace:
#0 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(203): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#1 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(231): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#2 /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/View.php(196): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#3 /Users/xxx/Sites/zf2helloworld/vendor/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(128): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#4 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#5 /Users/xxx/Sites/zf2helloworld/vendor/Zend/EventManager/Ev in /Users/xxx/Sites/zf2helloworld/vendor/Zend/View/Renderer/PhpRenderer.php on line 461
Am I missing the obvious? Why can the template not be found? I echoed back the 'template_path_stack' and it seems to be correct:
/Users/xxx/Sites/zf2helloworld/module/groupa/module1/view
I am aware of the reusability of modules and such. We would still love to group modules that belong together into the same folder and preferably access them via the proper URL (groupname/module).
Thank you for your time!

First of all, as per PSR-0 standard your classnames must have the following structure: \<Vendor Name>\(<Namespace>\)*<Class Name>.
Meaning that your module name should be <Vendor Name>\<Module\Name>
As for template name, by default FQCN of controller is converted to template like this First namespace/controller class name/controller action name
Meaning your Groupa\Module1\Controller\IndexController controller will give you template name groupa/index/index(and not groupa/module1/index/index as you might expect) which will be resolved to file groupa/index/index.phtml in paths defined in template_path_stack
This is default behaviour and it cannot be changed without backwards compatibility break. To mitigate that since zf2.3 there is new setting that will allow you to use modules the way you want.
It is controller_map under view_manager config section.
How to use that you can read here:
https://github.com/zendframework/zf2/pull/5670
'view_manager' => array(
'controller_map' => array(
// Groupa\Module1\Controller\IndexController -> groupa\module1\index\index
// -> module/Groupa/Module1/view/groupa/module1/index/index.phtml
'Groupa\Module1' => true,
),
);

Related

Prestashop - Multi Shop Associations - Missing Group name

Im making a multi shop module, the module saves / adds to the modules shop tables etc.
This part is fine.
I just have an issue with the GUI its missing the Group names, to me it looks like I'm missing something for a sprintf() I just see the %s and not the group name.
The image shows what I mean.
In my renderform function I have added.
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Shop association'),
'name' => 'checkBoxShopAsso',
'values' => Shop::getTree()
);
}
I wonder do i need to add anything else? all of the other modules I have look fine.
Thanks.
** Updated **
Have just found the template, it is the sprintf() that is not working because if i relace the line it works fine.
{*<label class="tree-toggler">{l s='Group: %s' sprintf=$node['name']}</label>*}
<label class="tree-toggler">{$node['name']}</label>
Any Ideas?
Thanks.

get some of my controllers in zend framework 2

I am createing a cms based on zend framework 2 . I have som modules , let's say News module.
It has two controllers one for backend and one for front page :
News Module :
-- AdminController
-- IndexController
My question is How can I list all AdminControllers in my admin module ?
I think it can be achieved by event manager but I don't know how
Thanks in advance
Your Admin module does this:
check a config key (i.e. super_cms)
check if a subkey exists (i.e. controllers)
foreach entries in said subkey, list them on your webpage
Your News module does this:
//module.config.php
return [
'super_cms' => [
'controllers' => [
'NewsModule\Controller\AdminController' => [
'label' => 'News',
'permission' => 'Admin',
'route' => 'news/admin'
]
]
]
];
Now with this setup, you could do a foreach on the controllers and create a navigation that has all your controllers listed that you need. You could specify dedicated label options, you could assign permission keys that are required for access or you could assign a dedicated route to call.
This is all up to you tho. But without configuration, nothing works. There are "magic" ways, yes, but they would all require you to recursively scan lots and lots of directories which you don't want! Seriously, you don't!

Yii - one controller multiple urls

I'm trying to create two Yii models that are very similar and can share the same database table. One is a 'question' and one is an 'article'. They both share a title, body, and author. 'Question' has an additional field in the table that 'article' does not need to interact with called follow_up.
Most methods and validation is the same, but there are some tiny differences that could easily be done with if statements. The main problem I'm seeing is the URL, I want separate URLs like site.com/question and site.com/article but have them both interact with the same model, controller, and views.
How can this be done?
Use the urlManager component in the Yii config to set routes for /article and /question to go to the same controller, and then either use different actions or different parameters to differentiate between the two. Since you said they are almost identical, I would suggest different parameters and a single action as follows:
array(
...
'components' => array(
...
'urlManager' => array(
'question/<\d+:id>' => 'mycontroller/myaction/type/question/id/<id>',
'article/<\d+:id>' => 'mycontroller/myaction/type/article/id/<id>',
),
),
);
Of course you'll have to modify that for your needs, but that's the general setup. Look here for more information: http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Magento API - Several methods do not work

I've got the following problem. I built a PHP file, which reads categories from a file, to impor tthem into Magento. I am able to read the file, no problem. The connection via NuSOAP to the Magento API works aswell. I can get the SessionID and I am able to get data, like Information for a category, also its possible to delete categories.
But, whenever I try to create or update anything, it throws an error. The rights for the user are ok aswell. For example, when I create a category, I add the usual data to the call:
$proxy->call(
$sessionId,
'category.create',
$rootCategory, array(
'name' => "TEST",
'is_active' => '1',
'page_layout' => 'two_columns_right',
'description' => "TEST",
'meta_title' => "TEST",
'meta_description' => '',
'meta_keywords' => "TEST",
'include_in_menu' => '0',
'display_mode' => 'PRODUCTS',
'available_sort_by' => 'price',
'default_sort_by' => 'price',
'is_anchor' => '0'
)
);
All the time, it says:
(
[faultcode] => 102
[faultstring] => Category not exists. )
Which is not true. The $rootCategory is definatly a category, which is existing. I tried all other categories, I tried to add a 'path' to the info, I tried to use less information (only the neccesary stuff), I tried to read existing categories to get their IDs, NOTHING works. It always throws this faultcode.
Same happens, when I try to update a category, or create /update a product. Deleting is no problem at all.
Do you see the problem?
i just compared your NON working exemple and i found this while comparing it with another exemple i has ( i do not pretent to be expert ) ..
but seems like your $new_category, array(blahblha) ...
should be INSIDE an array according to the exemple i already have
like this array($new_category,array(blahblah) ...
this is the mains difference i just saw ..
here is the EXEMPLE i just pulled out of the web ... Adapt to your needs..
$proxy->call(
$sessionId,
'category.create',
array(
3,
array(
'name'=>'New openerp',
'is_active'=>1,
'include_in_menu'=>2,
'available_sort_by'=>'position',
'default_sort_by'=>'position')) );
Have you tried specifying the category_id key in your $rootCategory within the call:
$selectedCategory['category_id'],
array('name'=>'New Category Through Soap')
)
Reference: http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_category

Cakephp, i18n, SQL Error, Not unique table/alias

I get the following SQL error:
SQL Error: 1066: Not unique table/alias: 'I18n__name'
when doing a simple find query.
Any ideas on possible situations that may have caused this??
I'm using a bindModel method to retrieve the data is that related?
This is my code:
$this->Project->bindModel(array(
'hasOne' => array(
'ProjectsCategories',
'FilterCategory' => array(
'className' => 'Category',
'foreignKey' => false,
'conditions' => array('FilterCategory.id = ProjectsCategories.category_id')
))));
$prlist = $this->Project->find('all', array(
'fields' => array('DISTINCT slug','name'),
'conditions' => array('FilterCategory.slug !='=>'uncategorised')
))
You have not used or initialized the required table/model you are using in your controller. Use var $uses = array('your_table_name');
I do not have a direct answer to my problem. However after some research I came to the following conclusion.
I've decided to change my methodology and stop using the translate behavior in cakephp.
I've found another behavior called i18n which works much better when dealing with associated models. You can read about it http://www.palivoda.eu/2008/04/i18n-in-cakephp-12-database-content-translation-part-2/#comment-1380
In cakephp book it says :
"Note that only fields of the model
you are directly doing find on will
be translated. Models attached via
associations won't be translated
because triggering callbacks on
associated models is currently not
supported."
I'm not sure if I made the right choice however I have been struggling to get the translate behavior to work in cakephp and this solution at least makes the project I'm working functional.