When to create a module in Yii2 Advanced template? - yii2

I am little confused before starting a new project in Yii2 advanced template. So, i am asking this question.
I have done some projects in "Yii2 basic" app in which we use modules for different parts of our application like for adminpanel, api we create different folders in 'modules folder'.
I had also done a project in Yii2 advanced template it was multiapp project so we used advanced template. As we already had 'backend' and 'frontend' separated in Yii2 advanced template so we didn't created any module in 'modules' folder.
Now, i want to ask what is right approach. like in my new project we have users and products in backend so is it appropriate to create different modules for them in 'modules' folder or will it be ok if i create there controllers and models directly in backend folder.
what are the advantages of using modules folder in advanced template?
Thanks for answers in advance.

The advantage of module's use is primarly the possibilities of a resue of this components in several diffferente project. you can easly separate you common repetative functionalities in several modules and use the same code in different prject indipendently of the "template" or scaffolding you use for the single applicazione or group of applications.
Do the fact the modules are self-contained software units that consist of models, views, controllers, and other supporting components
modules are, not only usable as a sort of mini-applications, but also as a easy way for code organization and reuse.

Modules are used to reduce our work.
Example:
In most of projects have user login function like login , signup ,
forget passsword ,password reset.
If you write code for these functions as module . You can use any
project
So there is know need to write one code again and again.

Related

Add custom Jinja2 filters/tests to MkDocs

While writing a Jinja2 template for MkDocs, I need some processing that is not covered by the filters/tests available (specifically, I need date formatting, which is a recurring example for custom filters in Jinja2-related resources across the Web). How can I define my own filters/tests and use them from templates?
To clarify the question, I know how to register new filters/tests in a Jinja2 environment from Python. My issue is that, as a user of MkDocs, I do not configure Jinja2 myself. So what I’m looking for is a way to hook into the setup that MkDocs performs.
I assume it is possible to add filters from a plugin. In fact, I have found one such plugin (undocumented and apparently not under active development, unfortunately). However, I hope that there is a simpler, local solution; one that would not involve implementing a plugin, packaging it as a Python package and publishing it on PyPi.
A possible solution is to use mkdocs-simple-hooks that allows to implement the hooks without needing to create a plugin. For example in your case:
plugins:
- mkdocs-simple-hooks:
hooks:
on_env: "docs.hooks:on_env"
docs/hooks.py
def on_env(env, config, files, **kwargs):
env.filters['my_filter'] = my_filter
env.tests['my_test'] = my_test
return env

PhpStorm - extend PHP Class template

I'm trying PhpStorm. I like the File Templates functionality and I'd like to use it in some more specific cases.
I'd like to extend to PHP Class template to create a new template that I'll be using for a specific type of classes. If I just duplicate the template, it doesn't really work as I'd expect. For example, while when I use PHP Class, the namespace is already compiled, this does not happen with my new template.
Is it possible to create another template so that it works as PHP Class?
Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?
Is it possible to create another template so that it works as PHP Class?
Unfortunately not; at least not in current versions (2016.2).
When you are using New | PHP Class you see special dialog box that works with 3 templates (depends on what you will be creating: Class, Interface or Trait). This dialog uses file templates with predefined (default) names only and you can customize them as you wish .. but all other file templates for .php files will be just ordinary File Templates without those extras.
Based on your requirements you might be interested in https://youtrack.jetbrains.com/issue/WI-21711 ticket -- watch it (star/vote/comment) to get notified on any progress.
Please note that file templates could be project-specific (different template content for each project) -- this might be enough in some (rather simple) cases.
Moreover... is there a way to order the templates in the editor, so I could have my new template near all the other PHP templates?
Unfortunately not -- no sorting/subfolders is available (although you may have project-specific file templates).
Right now I may only suggest to use some common prefix in template name and build your sorting order around this idea.
Other than that -- https://youtrack.jetbrains.com/issue/IDEA-75239 + https://youtrack.jetbrains.com/issue/IDEABKL-3599 -- watch these tickets (star/vote/comment) to get notified on any progress.

yii2: where do my project's own html, css, js, and php-include files go?

Choices:
create an asset bundle (nicely explained by Ivo Renkema at How do I manage assets in Yii2?). this is what I need if I want to package my code for other use. alas, should I also do this for my own php include library functions? Or should I still stick them into the same php location as my other php files? In any case, if I want to go this route, presumably I would then customize the AppAsset class, included in the template, as explained in http://www.yiiframework.com/doc-2.0/guide-structure-assets.html .
stick my files directly into $basePath/web, where $basePath is typically something like /var/www/myapp/ (i.e., as $basePath/html/mine.html [and refer to it simply as href='/html/mine.html'], $basePath/css/mine.css , $basePath/js/mine.js, and $basePath/php/mine.php [and refer to it as $basePath= \Yii::getAlias('#webroot'); require_once('$basepath/php/mine.php') ])?
stick my local files where my php view code sits. the advantage is that the files are close to where I will use them. the disadvantage is that I may litter the view directories not only with php files, but also with my non-asset assets, even though they will be used only by these (my) php files.
it's a beginner's question for the google cache reference. it's about best practice when getting started. I can guess the answer, but we wouldn't want a novice to disseminate bad info.
If you need your CSS and JS files only in one view or one Controller you have 2 choices:
1- Create a asset bundle Here other guide if you need it.
2- Use registerJsFile() from View Class
You can acces from controller using:
Yii::$app->view->registerJsFile('js.path');
(Same with CSS files but using registerCssFile())
With the PHPfiles I always try to convert the code to yii's MVC. If you have a entire library try to add it as a component. Here a usefull guide

Rename Taxonomy label in editor bolt-cms

I would like to rename the default tab value of Taxonomy in the backend page editor. I didn't find anything in the twig or yml files that would address this. Any ideas?
I checked with bolt developers and there is no way currently to do this. One potential option was to use the messages file but it was not recommended.
As you can imagine, since this isn't supported via the public configs, this will need a bit more advanced plugging together.
Here is a way to add an additional resource to the stack of translations.
https://gist.github.com/rossriley/c74fdee4fec3eaffb12f
This is a technique to add your own messages onto the translation stack without touching the underlying core files.
After creating this, you'll need to add your new service provider to the app, which you normally will bootstrap either in your index.php or a custom bootstrap file.

How to run sql query to return data from different joomla components

I am trying to customize the source files of a Joomla component.
Before the Joomla MVC model introduced, I was able to run SQL queries in a component, Kunena 1.0 to select data from another component. e.g Sobi2.
However, after Kunena 1.5 [MVC model] was introduced, I do not know how / where to add the SQL query to select data from Sobi2.
I believe I need to add some codes in the files of the /models/ or /func/ folder. But can someone provide more detailed assistance on how I can achieve this?
The data interaction is done by the model, you will find Kunena models in the model folder.
Querying the SOBI2 databse is the same as before, MVC wouldn't actually affect how you do this.
To get your head around MVC, have a look at:
http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
For examples of how to query the database in your model, look at:
http://docs.joomla.org/How_to_use_the_database_classes_in_your_script
In simple terms, the Controller directs to the appropriate view (view.html.php), this view then interacts with the model, and then directs to a template file (normally located in the view/tmpl folder.
Hope this helps.