get some of my controllers in zend framework 2 - module

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!

Related

What is the intention behind the product_configurator_settings table?

I am doing some research about variant handling in Shopware in general and was not able to find any relevant information about the table product_configurator_setting.
When you create a variant, then it is required to add the relevante property option id, the parent id and the variant id so that there will be a relation created.
[
'id' => $variantUuid,
'parentId' => $parentUuid,
'options' => [
[
'id' => $propertyGroupOptionId
]
]
];
However, there was an existing documentation which says, that an entry in the table product_configurator_setting is required. However, when i create variants in the Shopware-Backend, no such entry is created.
"configuratorSettings" => [
[
"productId" => $variantUuid,
"optionId" => $propertyGroupOptionId
]
],
So for clarification:
What is the intention for having the table product_configurator_setting and what is the difference to the options entry for variants?
Isn't the information redundant as it exist for variants?
Why is the entry mandatory in the documentation but it will not be created by Shopware when variants are created in the Admin UI.
The product_configurator_setting table in Shopware is used to map product variants to their corresponding configurator options when creating variants programmatically. This is different from the options array used in the Shopware backend to establish the relationship between a variant and its configurator option(s). While the product_configurator_setting table is mentioned as mandatory in some cases, it is not required when creating variants using the Shopware backend.

ZF2 Modules in Subfolders

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,
),
);

Access objects from project in sandbox environment PHP

Is there a way I can access my project under Sandbox? I'm able to use the lookup method, find in order to fetch all the features from a project under the Yahoo! subscription, but how would I be able to do this for projects under Sandbox?
In your PHP code have you used Rally sandbox server URL?
https://sandbox.rallydev.com/
Here is a WebServices URL specific to Sandbox:
https://sandbox.rallydev.com/slm/doc/webservice/
I was able to figure it out. In the query to find specific features, I had to include the query parameter "workspace" to the sandbox reference which is (for 1.43) : "https://rally1.rallydev.com/slm/webservice/1.43/workspace/7189290105.js". I included the reference of the project as well which directly fetched all the features for my project. In addition, if you seek to only fetch features from your specific project and not from the ones on top of it, you have to include the "pageScopeUp" field into the query. You have to set this field to false:
$queryParams = array(
'query' => "",
'fetch' => 'true',
'pagesize' => 100,
'start' => 1,
'workspace' => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/7189290105.js",
'project' => "whatever the project reference is",
'projectScopeUp' => false
);
$results = Connection::rally()->findWithQueryParameters('feature',
$queryParams);

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

CheckAccess. Agile Web Application Development with Yii1.1

I need some help with CheckAccess function.
I'm reading book Agile Web Application Development with Yii1.1 and PHP5, and came to page 212. On this page I've to added a "Create user" menu item.
I login with the user that is associated with the project (in Db table project_user_role) like a member, and members has operateion called 'createUser'.
The problem is that I can't see the menu item which should be generated by the following code:
if (Yii::app()->user->checkAccess('createUser', array('project' => $model))) {
$this->menu[] = array('label' => 'Add User To Project', 'url' => array('adduser', 'id' => $model->id));
}
Thanks
Also with AuthAssignment there are two more tables and even having them is not full deal. You got to have set RBAC :).
Please SeeRole-Based Access Control