Zf2 - Access layout from other module - php

I have Two modules Albums And Signup. I need to set layout in Signup module.My difficulty is here , i need to set a layout.phtml for a page in signup module , but layout.phtml is residing in Album module.

Try using the EdpModuleLayouts https://github.com/EvanDotPro/EdpModuleLayouts
"Using EdpModuleLayouts is very, very simple. In any module config or autoloaded config file simply specify the following:"
array(
'module_layouts' => array(
'Album' => 'layout/album',
'Signup' => 'layout/signup',
),
);

Related

ZF2 'unable to render template' when shifting module names in the array in app config

Good day.
I've just started learning ZF2, replicated the Album example step-by-step, and then decided to make it a bit more interesting by adding user registration, and then make the two work together in some way, so i added a new 'Auth' module.
So, when i only had one module in the module list (aside from the Application module) in application.config.php, it was all fine, but when i added the Auth module to the list like so:
'modules' => array('Application', 'Album','Auth',)
i got the following error when trying to access any views from the album module which was working absolutely fine prior to this change:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "album/album/index"; resolver could not resolve to a file
But when i changed the order in which the modules are presented in this array like so:
'modules' => array('Application', 'Auth','Album',)
not a single view (and it has only one) from the Auth module could be rendered, while the Album module was fine.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "auth/user/index"; resolver could not resolve to a file
Both of these views exist at these locations, but the renderer doesn't see them for some reason.
You can see the project's contents here.
Thank you for any tips in advance.
Looks like you copy pasted the the view manager config for Auth module.config.php.
This should be auth rather than album for your templates to work correctly.
'view_manager' => array(
'template_path_stack' => array(
'auth' => __DIR__ . '/../view',
),
),

Does not show newly created module in Layout

I'm trying to list my newly created module(account_test) that copied from "account" module in OpenCart 2.x (account module shows in backend system->design->layouts-> edit home layout). I have duplicated all account php & tpl files to account_test & tpl files and change all references from account to account_test in both admin & catalog module/language/view folders.
Also, I noticed in admin\controller\design\layout.php the if statement which add only Account & Category modules to Layouts setting:
if ($this->config->has($code . '_status') || $module_data) {
$data['extensions'][] = array(
'name' => $this->language->get('heading_title'),
'code' => $code,
'module' => $module_data
);
}
If i remove the if condition :
$data['extensions'][] = array(
'name' => $this->language->get('heading_title'),
'code' => $code,
'module' => $module_data
);
It will add all modules to layouts view, but none of them working except old modules
Stuck in this for few days, Any ideas to list newly created module to layouts admin section and front end?
Is you module get installed or not? If you followed correctly then it must be listed in admin->extension->modules. And then from there you have to first install it and then enable it. And also make sure the controller file named properly.
Edit
$this->config->has($code . '_status') checks whether you module is installed or not i.e. is it in setting table or not. Check in setting table for your module code.

Different interface layout for different level users in yii

I'm new to Yii. I'm developing a system with YII framework in PHP. How can I have a different layout for different module? I want the module A to have interface A, module B with interface B. But what I have know is that the interface login is the same for all module login. Can someone give me a light?
Update:
I found one way which is to include the:
$this->layout = $layout;
on the action function inside the controller before rendering the page. However, I found that it's not that efficient as on every action I need to repeat the line. Is there a way where we can do the setting on the config/main.php page? probably on this part:
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123',
'generatorPaths' => array('bootstrap.gii'),
),
'admin',
'consultant',
'client',
),
You can set variables for your module in your config like this:
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123',
'generatorPaths' => array('bootstrap.gii'),
),
'admin' => array(
'layout' => 'your_layout' //The layout for this module
),
'consultant',
'client',
),
This way you can implement a default layout for every single module. Without having to add controller methods or variables.
For more info see the docs: here and here
try this:
class YourController extends Controller {
public $layout = 'your_layout';
}

Changing CSS file in YII app doesn't work

I am trying to change the styling of the gridview, tableview, & detailview. I found something saying that I should change the config/main.php file to this:
...
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
'widgetFactory'=>array(
'widgets'=>array(
'CGridView'=>array(
'cssFile' => Yii::app()->request->baseUrl.'/css/table_and_grid.css',
),
),
),
...
I have removed the assets folder that is generated by the app, but that didn't help. When I load the view, I can see that the css sheet is being loaded into the header of the page, but none of the styling is working. Why? How do I fix?
I haven't seen anything about changing the style of CGridView in main config file(main.php), But you can customize CGridView styles with bellow parameters:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'SOME ID',
'dataProvider'=>$YOUR_DATA_PROVIDET,
'cssFile'=>'...',
'baseScriptUrl'=>'...',
'filterCssClass'=>'...',
'itemsCssClass'=>'...',
'pagerCssClass'=>'...',
'rowCssClass'=>'...',
'summaryCssClass'=>'...',
));
You can change ... with your own.
for more information you can check CGridView's Official document on the following link:
CGridView

Phalconphp routing for multimodule application

I've created a multimodule application using phalconphp developer tool:
phalcon project <projectname> module
And I've added a backend module (the frontend is generated). Now I would like all backend routing do the following:
$route->add('/admin/:controller/:action/:param', array(
'module' => 'backend',
'controller' => 1,
'action' => 2,
'params' => 3,
));
But my routing also defines:
$router->setDefaultModule("frontend");
$router->setDefaultNamespace("Groendesign\Backend\Controllers");
And therefor when I browse to: http://myprojectname/admin it searches in my backend module for the frontend Namespaces, How should I proceed with this?
What I want to achieve is that every url that has the prefix /admin/ is send to the backend module. Using the url to define which controller, action and parameters.
I've fixed this by removing the setDefaultNamespace from my bootstrap and adding it to the Modules.php file in each Module. Thereby setting the DefaultNamespace only in the correct module.

Categories