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

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

Related

Yii2 BaseUrl for bootstrap fonts

I need your help guys. I changed directory for all Assets. It works properly, but not for bootstrap fonts.
For Ex: path for css and js file now is project/www/web_assets/all.css and Yii2 found them properly.
But it does not working for fonts. Yii2 is looking for fonts at wrong derictrory /var/www/tt_yii/web/assets/582582f3/fonts/glyphicons-halflings-regular.woff2.
Bootstrap gets used at different places. It is already configured by default by the BootstrapAsset and is a dependency for other pre-defined assets. But you can override the default location.
Assuming you have the same file structure in web_assets as it can be found in 'vendor/bower-asset/bootstrap/dist' (contains folder css, fonts and js) you can add the following to your components configuration:
use yii\bootstrap\BootstrapAsset;
...
'components' => [
...
'assetManager' => [
'bundles' => [
BootstrapAsset::class => [
'sourcePath' => null,
'baseUrl' => '#web/web_assets',
],
]
],
...
],
#web points to the web folder where the index.php and your web_assets directory file should exist as well. sourcePath gets set to null since baseUrl wouldn't be evaluated.
Further information about configuring the used bundles can be found at AssetManager::$bundles or in the guide.
Similar question is here.
Check you nginx settings. If there is a filetype list, you should insert these font types into it also:
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|eot|svg|ttf|woff|woff2)$
(Duplicate of bootstrap icon fonts not loading )

Yii2 Modules in advanced template

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

How change view folder in Laravel5?

I am developing an web application using Laravel 5 and AngularJS. I am using pure angularJS app for the client side and I am putting the client app files (views) in my public folder.
In Laravel 4, I could change the path from the bootstrap/start.php file. But in Laravel 5, I can not see the start.php file. So where do I change the configuration in Laravel 5?
See line 16 of config/view.php (the "View Storage Paths" section)
'paths' => [
realpath(base_path('resources/views'))
],
So you might change it to realpath(base_path('public/assets/views')) to be in your public path.
Additional Examples
'paths' => [
// src/MyNamespace/resources
realpath(base_path('src/MyNamespace/resources')),
// app/resources
realpath(app_path('resources'))
],
You can provide multiple search locations
You can use app_path(), base_path(), or neither.

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

URL cannot be found on the server for my FuelPHP Module

I'm creating a small FuelPHP application that contains a blog module. In this module the posts controller just assigns a simple view to the template for the posts index.
I have read through the FuelPHP docs and have the following settings in the app config for the modules:
'module_paths' => array(
APPPATH.'modules'.DS,
APPPATH.'..'.DS.'globalmods'.DS
),
'always_load' => array(
'packages' => array(
'auth',
'orm',
),
'modules' => array(
'admin',
'blog',
),
),
The application itself is outside my WAMP www docroot but the assets, htaccess and index.php are inside.
I have no idea why the server cannot find the localhost/blog/posts/index URL as I have followed everything advised on the docs and the homepage (root route) seems to display fine. It is only when I click the blog link (blog/posts/index) that it states
"Not Found
The requested URL /blog/posts/index was not found on this server."
Any help would be much appreciated!
I had the same problem myself. Two key things I did were:
1) Start with a fresh copy of Fuel. I was missing some sort of configuration file, so I create a brand new Fuel framework, and then added all the app files back in
2) Enabling the 'rewrite_module' in the Apache Modules (in the Wampserver config)
Try these two things and see what you get.

Categories