Yii2 Modules in advanced template - php

I want to create a module (for example Users) in an advanced template application, that I could use it both in the backend (CRUD functionality) and frontend (login, profile)
Which is the right way of doing it, without having to create one module in backend and another in frontend and maybe a model in the common folder?
I want all files in one folder.

The simplest way for for create a module that you can use both backend and frontend and easily reusable also in other project is create the module in a your vendor dir eg:
vendor\yourvendorname\modulename\Module.php
then create the necessary dir
vendor\yourvendorname\modulename\controllers
vendor\yourvendorname\modulename\models
vendor\yourvendorname\modulename\views
the module name in module section config\main.php
'modules' => [
...
'modulename' => [ // dfenx module for migration via web without console command
'class' => 'vendor\youvendorname\yourmodulename\Module',
],
then refer to the module in you url eg:
yourprojectname/backend/web/index.php/modulename/controller
you can refer to this guide for tutorial

Related

How to include bootstrap and jquery in my Laravel package

I am making a package for Laravel 5 that will use bootstrap 3 and jquery.
How to include these assets in my package properly?
What if a person who will use my package will already have bootstrap and jquery in his/her project? Is it necessary to check that?
I can put them in my folder assets of the package, but what if these assets are in the project already?
You can not check if the project already has these assets, but if you want to include your own as part of the package you can do so with a provider.
Make a provider and register it in config/app.php (if your package doesn't have one already) and inside the boot() method you can "publish" (copy) assets from your package folder into the public folder of the Laravel application.
$this->publishes( [
realpath( base_path( 'your/package/folder/with/assets' ) ) => public_path( 'desired/folder/in/public' )
], 'public' );
If you are using default files without any modifications. then it is better to use from online repository, As keeping it public may override users custom settings. and it is wise to keep the package as small as possible.
And also you cannot check the whole project of user for these files

Can't find protected folder in Yii2 Basic Package

I'm new to Yii2 and I was wondering where the protected/config/main.php sitting? Is web.php the main config file?
Respect to yii1 the (in part) configuration is in
basic\config\web.php
and part is in
basic\config\db.php
There is also an advanced template where you have frontend and backend application soon available with proper separated config area ..

Yii2- how open generated module in browser (what url)

I have created module "Admin" in gii generator in Yii2 (my module is named "Admin" and it could be found here app\modules\admin\Admin.php)
But how can I open this module in my browser. What url I should use.
Url https://regexp/web/index.php?r=admin returns 404
To use a module in an application, simply configure the application by listing the module in the modules property of the application. The following code in the application configuration uses the forum module:
[
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Admin',
// ... other configurations for the module ...
],
],
]
The modules property takes an array of module configurations. Each array key represents a module ID which uniquely identifies the module among all modules in the application, and the corresponding array value is a configuration for creating the module.
See also Yii2 modules guide
If you have a controller named 'site' and an action named 'action', then to open them in the module 'admin', you should be able to do it with this URL: https://regexp/web/index.php?r=admin/site/action

ZF2 Default Routing Configuration

I am having trouble with the workflow when creating new modules/controllers to the ZF2 Skeleton Application.
I created a new module test and navigated to mydomain/test. This returns a 404 error until I do the following:
Define my Module in the global config file
Define my route in my module config file
Define my Controller as an invokables in the module config file
Define the path of my view as a view_manager in the module Config file
I am new to ZF2 and trying to better understand the workflow for Application development. This seems like a very cumbersome way to develop, as there is so much configuration needed.
(Rapid application Development??)
Is there a Default means of defining literal routes, controllers, and view rendering in ZF2?
Create your module with zftool, it will add it to your global config.
You will have to create at least one route for each module, take a look at the route in the Application module with this route you're covering allot the comment says:
The following is a route to simplify getting started creating new
controllers and actions without needing to create a new module. Simply
drop new controllers in, and you can access them using the path
/application/:controller/:action
You will have to add controller to the invokables
Use template_path_stack:
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
)
i use template_path_stack during development and template_map in production

How to add a rule to the Zend URL mapping and compose multiple MVC paths?

This is because I want to develop a web platform with more than one application in the same project.
In any MVC web application we should have this default URL schema:
domain/controller/action/parameters
1: In Zend, what can I do (in which files) to change this schema to add the application name before the controller name?
Expected Result: domain/application/controller/action/parameters
2: How can I implement the consequences of this new URL block in terms that I will separate the MVC for each application, maintaining the shared resources in a separate directory? What changes may I do in Zend autoloader
Expected Result:
/public_html/
/public_html/platform
/public_html/platform/apps
/public_html/platform/apps/base (user interface container)
/public_html/platform/apps/crm
/public_html/platform/apps/crm/model
/public_html/platform/apps/crm/view
/public_html/platform/apps/crm/control
/public_html/platform/apps/crm/public
/public_html/platform/apps/crm/public/css (and etc.)
/public_html/platform/apps/erp
/public_html/platform/apps/erp/model
/public_html/platform/apps/erp/view
/public_html/platform/apps/erp/control
/public_html/platform/apps/erp/public
/public_html/platform/apps/erp/public/js (and etc.)
/public_html/platform/sys
/public_html/platform/sys/core
/public_html/platform/sys/cfg
/public_html/platform/libs/
/public_html/platform/libs/zend
/public_html/platform/libs/template_it
/public_html/platform/libs/custom
i think it is as easy as having actual different ZF2 application, every one in its own folder, and in the same level, a "vendor" folder where you put all the shared structure (coming from zend, third party libraries, etc).
Then inside the vendor folder, i would create another folder for your own shared code, including all your modules that has to be used by more than one of the applications, so your code is a library for yourself.
Since your app is actually in domain/application, and everyone has it own config, it is very straightforward to have domain/application/controller/action/parameters routes: you just create your normal controller/action/parameters routes, since the app actually resides in domain/application/ and the router doesnt have to care about it.
As you noticed, another problem is the autoloader. YOu just need to update the references to the shared modules inside your application.config.php for everyone of your apps
return array(
'modules' => array( //....
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php'
),
'config_cache_enabled' => false,
'cache_dir' => 'data/cache',
'module_paths' => array(
'./module',
'../vendor',//reference to your library modules
),
),
//...
);
of course, if the modules doesnt reside directly inside vendor/module but something like vendor/libraryname/module, you have to take a look at your autoload system (Composer autoloading or whatever) and add the classes or namespaces to the corresponding maps.

Categories