How to best method create multi theme in yii2? - yii2

In my project I need to organize multitemnost.
But it does not fit just different CSS files, my theme should be completely independent of each other.
All that comes to my mind is
my db:
user
-id
-other_colums*
themes:
-id
-other_colums
current_theme:
-id
-user_id
-theme_id
View code:
$param = get value from current_theme;
return $ this-> render ("{$param}-viewname");
so I have bad multi theme system.
How better make it in Yii2 ?

If use simple themes without active forms and widgets is simple:
for each theme create asset bundle
for each view create own view view/{theme}_index
Real integration is complicate. For each theme:
create asset bundles for each functionality (forms, tables, wizards)
create extended widgets for theme
extend ActiveFileds - complicated
create layouts
create views (optional)
...
Example: https://github.com/mithun12000/adminUI

Related

Is conditional template overriding part of the Jekyll framework?

I'm interested in using Jekyll to host a dozen business websites that share a lot of information and web interfaces in common. Hence, I'm curious if what I'm about to ask is easily supported by Jekyll.
If this were another website platform like WordPress, Magento, etc.. etc... I might set up default templates for my website like this:
tpl/default/header.html
tpl/default/footer.html
tpl/default/privacy-policy.html
tpl/default/pricing.html
tpl/default/contact/map.html
tpl/default/contact/form.html
Then for each business that signs up with me, I will set up a folder for them called tpl/<businessname>/. Then, the platform will create a website using all the html files in the tpl/<businessname>/ directory. Whenever a template does not exist in the tpl/<businessname> directory, then the platform will use the corresponding template in the tpl/default/ directory.
As an example, let's say Bicycle Shop wants a website from me. I go ahead and create this:
tpl/bicycyle-shop/contact/map.html
Then in my layout files, I might make calls like this:
<?php
define('ORG','bicycle-shop');
put_tmpl('contact/form.html'); // this will use tpl/default/contact/form.html
put_tmpl('contact/map.html'); // this will use tpl/bicycle-shop/contact/map.html
function put_tmpl($tplname) {
if(file_exists('tpl/'.ORG.'/'.$tplname))
include('tpl/'.ORG'.'/'.$tplname);
else
include('tpl/default/'.explode('/',$tplname)[count(explode('/',$tplname))-1]);
}
?>
I'm curious how a behaviour like this is achieved in Jekyll?
ADDITIONAL
One way that just occurred to me was to have a _config.yml that has variables like:
tmpl:
home: tpl/default/header.html
pricing: tpl/default/pricing.html
...etc...
Then each business has _config<businessname>.yml that overrides the appropriate tmpl variables. Would that be the Jekyll convention? Or is there something out of the box with Jekyll that does this better?
There are themes... you just install a theme as a gem in your config. When you need to override a theme file, you just put that file in your _layouts or _includes directory.
Super simple.

When to create a module in Yii2 Advanced template?

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.

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.

Cakephp 2.4.5 Custom HTML in baked views

I have been reviewing documentation in the cookbook to generate custom HTML in baked views and I'm having difficulty in getting my custom code to run during the bake process.
I followed the instructions as stated which are:
Modify default HTML produced by “baked” templates¶
If you wish to modify the default HTML output produced by the “bake” command, follow these simple steps as outline at http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html
For baking custom views
Go into: lib/Cake/Console/Templates/default/views
Notice the 4 files there
Copy them to your: app/Console/Templates/[themename]/views
Make changes to the HTML output to control the way “bake” builds your views
The [themename] path segment should be the name of the bake theme that you are creating. Bake theme names need to be unique, so don’t use ‘default’.
For my "theme" I chose the name dalma and placed my modified versions of the view generation code in
app/Console/Templates/dalma/views/
and then rebaked a specific table and none of my changes appeared.
I had assumed that I would be prompted for a theme when I ran the bake from the CLI which was not the case.
I then found instructions which talk about assigning a theme in the AppController which I did and this did not help.
Next I found another article http://www.dereuromark.de/2010/06/22/cake-bake-custom-templates/ that talked about placing the custom code in the app/vendors/shells/dalma/ directory and this did not work
I would appreciate any assistance.
You have to have a layout specified in your appController that matches the folder name in Console/Templates
appController.php
public function beforeFilter(){
$this->layout = 'bootstrap';
}
Console/Templates/bootstrap has my bake template.
With this setup the bake console prompts me for a template choice. (there may be other ways to specify this)
Here is my custom bake template which should help. (this is a forked work and not all my original code)
https://github.com/arco000/BootstrapCake

Organizing a large number of classes under a Namespace

We are converting windows applications to browser based in .Net using Visual Studio 2010. While I'm not new to .Net, I am new to creating applications based on 3 tier architecture. I want to create classes for each table in our database and put them under a Namespace. The class name will be the same as the table name, so each class in the the Namespace would be referenced something like CompanyName.ProductName.Entity.{table name}. Now for my questions:
Is this feasable?
Would I create seperate project for each table class? Note that new table classes will be created as more programs are converted.
Does this create one huge .dll?
How do other developers access the classes I created, and where are they stored so I can reference the classes with the Using directive?
Always create the class names with individual cs file, so it will be easy to do versioning of files. It does not relate to size of dll if we keep the class in a single file or multiple files.
Create the folder structure like Project > ProductName > Classes in your solution.
Would I create seperate project for each table class?
No, don't create a separate project for each table class. That's too granular.
Does this create one huge .dll?
Each project would create a separate DLL by default (I believe you can do things with IL merge to change that.) However, each namespace does not have a direct relationship to DLLs. That is, you can have multiple namespaces in a single DLL.
What we've typically done is create a DAL library. This would be it's own project, usually named something like ProductName.Data Then within that we might have a namespace like ProductName.Data.Models or ProductName.Data.Repositories.
Namespaces are largely used to help YOU organize the code. They also help out the compiler. For example, if you have a database class named Users, and it's in XYZ.Data, you can still have a view model named Users if it's in a separate namespace, e.g. XYZ.ViewModels.
Another thing that we've done is to keep the root namespace the same across DLLs for the same product. So we recently had our database in XYZ.Data. Then we put our application specific logic in a separate DLL and named it XYZ.AppLogic We also had view models in the namespace XYZ.ViewModels.
I don't believe there are any hard/fast rules that limit the number of namespaces you have. By default, Studio will try to create a new namespace for each folder in your project. That said, I often try to avoid namespace overload, because I don't want to see something like this at the top of my files:
using XYZ.Data.Models.Accounts;
using XYZ.Data.Models.Users;
using XYZ.AppLogic.Authentication;
using XYZ.AppLogic.Users;
using XYZ.AppLogic.Settings;
using XYZ.ViewModels.UserPreferences;
However, that's more of a personal preference than anything else.
EDIT Solution View
MySolution
MyProj.Data
Models
User.cs
Account.cs
Settings.cs
Repository
UserRepository.cs
AccountRepository.cs
User.cs is my POCO (Plain Ol' CLR Object) that defines the table.
The Repository folder has things specific to my ORM (I'm using PetaPoco) which let me actually access my user data.
For example, my UserRepository might have a method
public User GetById(int id)
{
var db = new Database(<myConnectionStringName>);
return db.SingleOrDefault<User>(id);
}
That syntax is specific to PetaPoco, but it is how I separate the data object from the actual DB connection.
The simple answer that I was looking for is to create one solution with my namespace as the default namespace. For each file, create a new class, and specify the namespace in each. Thanks to all who responded.