Yii - Using alternate view file in Yii User module - module

Is it possible to use a custom view file in a module (eg. user) in order to keep the module (3rd party) intact?
Somehow extend the module, with a views folder that holds my custom views.

The path to the module theme views should be
/{{your_app_name}}/themes/{{theme_name}}/views/user/
Copy all of the module views from the folder
/{{your_app_name}}/protected/modules/user/views
to the mentioned above folder and that will do the job. After that you could customize the views as you like.

Copy user module view files to <app>/themes/<current_theme>/views/user/. More general, customize module views using the folowing "formula": <app>/themes/<current_tehem>/views/<modules_name>/<controller_name>/<view_file_to_customize>.php

Use a theme. For a module named "user" and a view path of "profile/edit", create "/themes/flashy/user/views/profile/edit.php". You can also define a new layout in "/themes/flashy/layouts/column2.php". Then add to your configuration file in "protected/config":
return array(
// many settings...
'theme' => 'flashy',
For the module "user" you pointed out, unfortunately its controllers use absolute paths for their layouts (e.g. "//layouts/columns2") so AFAIK you can't define distinct layouts for the application and this module.
See also the official guide chapter on theming with Yii.

I disagree that in many help forums of the Internet, when someone asks abot theming a module, everyone suggests a path alias to the themes folder. I think this is wrong, because it implies modules to be splitted, and modules are supposed to be a black-box that can be used across projects. The advice given in such forums would only be valid if a theme is shared among several modules. If someone wants to "package" a theme inside a module, she can:
-add an init function to the controller of the module
-inside that init, use the class attribute layout and a path alias, like this, supose a module whose id is "Sample":
then you add, to SampleCOntroller.php:
public function init() {
//BELOW: it will use the layouts/main.php inside the module.
$this->layouts = "sample.views.layouts.main";
}

Related

Need help on a minimal module for prestashop 1.7.x

I would like to write a module for prestashop 1.7.x for the first time !
It would be nice if someone could give me a hint how to start up.
I would like to use a php function with smarty call like {$page.page_name|test}
Hi #Hardy Thiergart and welcome to SO!
You can easily write your first PrestaShop module by following the tutorial here:
https://devdocs.prestashop.com/1.7/modules/creation/
Main steps:
Create a folder with your module's name
Create a PHP file with the same name
Make sure your PHP file contains at least the __construct(), install(), uninstall() and getContent() methods (the last one is required only if you allow users to 'Configure' this module)
You can then add additional methods for Hooks, including calls to your template files
Once ready, create a zip file of this folder, with your module's name
I hope this helps.
Here is a link to generate an empty Prestashop module with hooks, etc ... : https://validator.prestashop.com/auth/login
Regards

Using Favourites with Products in shoutem builder

I've been using / testing the new Shoutem builder, and I've installed both the products and the favourites extensions but am wondering on how I can "link" the two in between. So a user can favourite a specific product and store it in a little dropdown menu. I've searched the documentation and sample apps and I haven't seen the both used in action. Actually I haven't seen the Favourites extension used. Can this be easily accomplished by linking the two extensions?
I am looking for a starting point. So if anyone can guide or link me in the right direction that would be interesting.
Thanks.
This is not documented yet, but we have it implemented. You can check Books extension. It does just what you're looking for. It requires some changes on Product extension. You can check here how you can modify existing extension.
The app folder of extension is what is bundled inside of the app. That said, everything that extension exposes in its app/index.js is the public API, which can be imported directly inside of the other extension:
import {
Screen
} from 'tom.restaurants'
...where tom is used as example for developer name and restaurants for example for extension name.
All extension share the global app state, which is divided into extension sub-states prefixed by extension full name:
{
'tom.restaurnats': {
// state of 'tom.restaurants' extension
}
}
This way, you can make the 2 extension communicate.
I would recommend you checking out these 2 guides:
Technical overview - explains how the extensions are structured inside the app
Modifying extension - explains how to use parts from other extensions inside of your extension

SilverStripe 3: Can a module extend mysite/code/Page.php?

Good afternoon,
I don't know if what I want to do is possible, so here goes.
I have a module that extends Page_Controller, but I want certain functions to be accessible via the site root.
Eg: getMyDataObjectList();
Currently, they only work if I go through the normal MVC routing structure.
I've found that when I place the function 'getMyDataObjectList' within '/mysite/code/Page.php' it works.The problem is, I don't want to place the code in there. I want it bundled with my Custom Module, but to work the same as though it was in 'mysite/code/Page.php'
[Example Scenario]
site root: http://[somesite].com
By default, the 'Page.ss' template loads.
I would like the theme developer to be able to call my module functions (API) within any template/Layout page, and have the result returned from the site root
Currently, this only works if I move the "API" functions to '/mysite/code/Page.php'
If the code is in my module, then data is only returned when you go to:
http://[somesite].com/[module_controller]
Can this be achieved? If so, how?
Thanks for your assistance.
[Update - Code Solution]
///>MyExtension.php
class MyExtension extends Extension{
public function getMyDataObjectList(){
return 'object list goes here!';
}
}//class
///>[Module] => _config.php
Object::add_extension('Page_Controller', 'MyExtension');
And as always, I do a (/dev/build?flush=1) just in case.
Thanks to: 'simon_w'
Yes, this is relatively straightforward. Simply, create an Extension subclass with your methods in them and then add that to Page_Controller. An Extension subclass is almost exactly the same as a DataExtension, they're just for classes other than DataObjects.

Sylius theming and multilanguage

im new to sylius and wanted to know does sylius have theming and multilanguage? I cant find multilanguage option anywhere only language selection. And themes should be awesome feature still cant find that. Thank for reply.
Now Sylius is having theming facilities:
http://docs.sylius.org/en/latest/bundles/SyliusThemeBundle/index.html
Short explanation:
Themes reside in the 'app/themes/' folder (you can have multiple folders with different themes). The only required part for setting the theme is a composer file within the folder (each respective folders) and just add the name parameter. eg.
{
"name": "theme-name"
}
for having a grouping of themes you can also have the name like 'group-name/theme-name'.
You need to activate your theme in your config file. For that, just add
sylius_theme:
sources:
filesystem: ~
Now when you are in the administrative panel at the backend, you can select this theme from the dropdown list while customising a 'Channel'.
You can also override any bundle and customise it. For details please check the documentation.
As of version 0.13 it now is fully i18n. You can even add translatable entities using the ResourceBundle.

Where should I put my custom widget files in Yii framework?

From this page,
http://www.yiiframework.com/wiki/23/how-to-create-a-breadcrumb-widget/
It seems it suggests that we should put the files in the component folder. But if my widget contains javascript and css files, where should these files be placed?
By the way, is this a good idea that I create it as an extension? If I go this way, all widget files are more self-contained in a folder inside the extension folder. But since the widget I am going to work on is very customized, it's unlikely that it will be useful to other people or my other projects. Making it an extension seems a little bit strange.
I understand that it does not really matter where I put these files as long as the paths I am using in the codes are correct but I would like to know the common practice.
I think the common practice is to put the widget in extensions folder with js & css files in an folder named asset. In the php class file, you do initialization first by publishing the asset with yii asset manager.
The file structure may be like
extensions/
widget_name/
widget.class.php
assets/
plugin.js
style.css
I would join the recommendation to put the widget under /protected/extensions.
I put the assets in a slightly more detailed manner: /protected/extensions/WidgetClassName/assets/ and the widget view files in /protected/extensions/WidgetClassName/views/...
Don't forget to edit your /protected/config/main.php and add a row in the 'import' section (for autoloading of the widget): 'ext.WidgetClassName.WidgetClassName.*'