How to setup Yii2 module on subdomain correctly? - php

I have a project on Yii2 advances app. And I have created a module named 'sale' on front end, Where I have extended layouts of frontend. And now I just want to access that module as a subdomain like http://sale.example.com .
I have created subdomain sale.example.com and set it's document root to root folder public_html (sites's root folder).
I have configures my urlManager like 'http://sale.example.com' => 'sale/default/index', according to Yii2 DOC. And it working fine but all my navigation gone wrong. I mean I think app's homeUrl is not pointing to default site url. My entire url system is changed after sub domains like http://sale.example.com/contact, But this is supposed to be http://example.com/contact . Here is a snapshot.
Thanks in Advance.

You can do it using UrlManager. Here is example Just replace your_module_name with real name of your module. More on UrlManager you can see here
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'sale.example.com/<controller>/<action>' => 'your_module_name/<controller>/<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- 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

CakePHP projects Session not working

I've to CakePHP projects like:
project1 (main domain: http://www.example1.com)
/app
...
/project2 (sub folder domain: http://www.example2.com)
When hitting url for project1 it's working fine, but when visiting the project2, the $this->Session->write() isn't working, ie. Session is not working.
Write now this is session to project2/app/Config/core.php:
Configure::write('Session', array(
'defaults' => 'php',
'cookie' => 'project2_cookie_service',
//'timeout' => 525949
));
Please help me to resolve this issue.
In your app/Config/core.php change Session.cookie to another name. Your root project takes the default name CAKEPHP so change it for the sub-domain project to get another session.
From the following resource, you are able to change session save path of the project2 to prevent interference between it and project1 :
Configure::write('Session', array(
'defaults' => 'php',
'ini' => array(
'session.cookie_path' => '/app/dir'
)
));
Checkout this official resource

Project folder is taken as controller in zend project

I am setting a demo Zend project on a windows server.
That is having base url like http://example.com/JPZend/public/
But on some url like http://example.com/JPZend/public/user/index?page=2
it gives the following page not found error where http://example.com/JPZend/public/user runs perfectly.
Page not found
Exception information:
Message: Invalid controller specified (JPZend)
Request Parameters:
array (
'controller' => 'JPZend',
'action' => 'public',
'user' => 'index',
'module' => 'default',
'page' => '2',
)
What am I missing? Seems like some virtual hosting issue?
Normally, you use the public folder as your webroot.
So your URL would look like this: http://example.com/JPZend
The default route in ZF is:
:controller/:action
Or with Modules enabled:
:module/:controller/:action
To tell ZF that you have another Base URL, you need to add a line to you application.ini:
resources.frontController.baseUrl = /JPZend/public
And to your .htaccess or similar under windows:
RewriteEngine on
RewriteBase /JPZend/public
Have fun!

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