What to choose for Yii based website: subdomains pointing to modules or separate yii-applications - module

I'm making a website on yii which has several separate parts, each on it's own subdomain like themes.example.com, events.example.com etc with main page example.com where these parts are listed. I will also need to authenticate users across subdomains. So i'm thinking what would be better: making each part as a yii module or making a separate yii application for each of these parts?

I think in your case it would be better to use modules. At least to have a single webroot directory. Using separate yii application would be appropriate for console part of your project.
See this link for more information: The directory structure of the Yii project site

Well,
The features you are trying to accomplish from Yii its called "Parameterizing Hostnames". You need to create a module based structure in Yii.
At first you need to create a virtual host from apache and redirect that to your Yii project. On you Yii framework you need to change the URL manager from config.
'components' => array(
...
'urlManager' => array(
'rules' => array(
'http://admin.example.com' => 'admin/site/index',
'http://admin.example.com/login' => 'admin/site/login',
),
),
...
),
To know more about Parameterizing Hostnames

Related

Get data from username based url in YII framework

I am using Yii framework to develop my website. I didn't activate any URL manager in my main.php file and every thing is working fine with the default url structure. But now i want get the data of user from the below url manner
www.projectname.com/username.
But as per the current url structure, i am unable to get the data and it is showing requested url not found on this server.
When I type www.projectname.com/index.php/username then it is working but users will not enter index.php and it is not good manner as i know.
So can anyone please guide me to get the data when the user enter the url like
www.projectname.com/username
If your Username Controller Then
Use This In your config main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<username>' => 'user/profile',
You need to remove index.php from the url. You can follow this link to learn how to do it.

Is it possible to auto bootstrap all registered modules?

I have structure for multimodule app, but can't understand how I can register some routes from Module.php and fire event from one module and listen for it in another. Is it possible?
Some php frameworks register all modules before routing. For example, Zend Framework will loop through every registered module and load its bootstrap information. It will then parse the route and execute the targeted controller. The benefit is that you can do hierarchical mvc calls between modules. The drawback is you have a lot of overhead if you aren't planning on doing anything with all of those modules you bootstrapped.
To streamline the bootstrap process and load more quickly, Phalcon's framework determines the route before loading any files in the registered modules. It does not load the module.php file in each module, but instead only loads the module.php file that sits in the path of the route that will be executed. The benefit here is speed. The drawback is in trying to do hierarchical mvc across modules. At this point, phalcon has only bootstrapped the routed module, so is agnostic of any other modules.
Essentially, this means that you can only do hmvc requests within the current module. Likewise, the dispatcher in phalcon can only redirect to controllers and actions within the same module. If you need to go to another module, you can do a 301 redirect using the response->redirect action. Of course, this will generate an entirely new http request, so will not fit the hmvc paradigm.
One way to expand this functionality is to register a set of common namespaces that sit outside the modules. You can load these namespaces during the initial boot sequence started from the index.php file:
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
array(
'Common\Controllers' => COMMON_PATH . '/controllers/' ,
'Common\Forms' => COMMON_PATH . '/forms/' ,
'Common\Models' => COMMON_PATH . '/models/' ,
'Common\Models\ViewHelpers' => COMMON_PATH . '/models/ViewHelpers/' ,
'Common\Plugins' => COMMON_PATH . '/plugins/' ,
)
);
// each module will register its own namespace separately
$loader->register();
return $loader;
In each module's Module.php bootstrap file, you will add the additional namespaces for your given module:
/**
* Register a specific autoloader for the module
*/
public function registerAutoloaders(){
$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
array(
$this->_module_name . '\Controllers' => __DIR__ . '/controllers/' ,
$this->_module_name . '\Models' => __DIR__ . '/models/' ,
$this->_module_name . '\Forms' => __DIR__ . '/forms/' ,
)
);
$loader->register();
}
Now you have namespace access to call classes in the common namespace as well as namespace access to classes in the current module's namespace:
$common_model = new \Common\Models\MyModel();
$module_model = new \CurrentModuleName\Models\MyModel();

Install drupal in a directory beside an existing website

I want to Install a drupal website on the server in a subdirectory to use some of it's features for my main website, I dont want the installation affect the current website in any way.
the actual reason for doing this is that for example I would be able to use news section of drupal for main website.
so for instance, I install drupal on "drupal" subdirectory like www.mydomain.com/drupal , then when I configure and run the news section it will be like www.mydomain.com/drupal/news, what I want is when a user goes to www.mydomain.com/news, it loads www.mydomain.com/drupal/news instead.
I'd really appreciate any proper approach and suggestions to achieve this.
If I correctly understand your question that you want to have URLs like:
http://example.com/news/headline-test
But using Drupal's URL http://example.com/drupal/news/headline-test to provide the content of the first URL, you should use Apache rewrites.
Here is an example:
Add this to your top .htaccess folder (http://example.com/.htaccess - not publicly accessible yes):
RewriteEngine on
RewriteRule ^news/(.*) drupal/news/$1
See the Apache rewrite document for more examples/help.
Drupal cannot take over any folder if there is another file exists or it's pointing to another folder. But in this case, both of your http://example.com/drupal/news/headline-test and http://example.com/news/headline-test URLs will show the same content.
Do not edit Drupal's $base_url setting. Let Drupal figure it out. Also, add some robots.txt disallows to prevent content duplication. Block drupal's native URLs.
Take a look at redirect module.
OR
Create a custom module with hook_menu implementation
function MY_MODULE_menu()
{
$items = array();
$items['news'] = array(
'title' => 'news redirect',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'drupal_goto',
'page arguments' => array('drupal/news'),
);
return $items;
}

API subdomain for Heroku app, is it possible?

I am trying to build an API and I am concerned that all my resources will either not be accessible with the api.myapp.com domain or that they will "live" with the wrong uris.
I have added the CNAME for my domain name to point to my Heroku app.
(ex: browsing to www.myapp.com takes you to https://myherokuapp.heroku.com)
I would like to set up an API subdomain, so that a GET to
https://api.myapp.com takes you to https://myherokuapp.heroku.com/api/v1
The best scenario would be that a POST to https://api.myapp.com/accounts/12345 would create a new account. Is that even possible?
(I know that subdomains (eg: mysubdomain.myappname.heroku.com) are not possible with Heroku)
I believe the answer could be in three different places:
Something to do with DNS provider forwarding configs (maybe
something to do with "A" records).
Something to config in Heroku, possibly a paid add-on to handle domains/subdomains.
Handle all subdomains within my app.
If you want to differentiate between api.mydomain.com and www.mydomain.com and have different controllers for your API requests then you could certainly use Rails routes constrained to your api subdomain to handle this
constraints :subdomain => "api" do
scope :module => "api", :as => "api" do
resources :posts
end
end
which would then use the posts_controller.rb in the app/controllers/api folder of your application.
You'll then have both www.mydomain.com and api.mydomain.com added a custom domains for your application and then the routes will take care of the rest.
You might also want to look into the Grape Gem for helping build your api

Devise Authentication for users from Multiple GApps Domains

I have a rails app with Devise 1.4.9. Currently, it allows only users from mydomain.com to use the application. I need to open it up to some contractors that work for me. Their domain is theirdomain.com.
How do I expand this line from the OmniAuth guide to allow users from two domains?
config.omniauth :google_apps, :store => OpenID::Store::Filesystem.new('/tmp'), :domain => 'mydomain.com'
Include 'theirdomain.com' as well.
And also, how do I write a test for it? I've already written spec tests with sign_in_user "test", but they pass even without "test#mydomain.com". I don't have an account on their domain so cannot test easily.
Thanks!
This doesn't seem like it'll work. I did a deep dive into the gem code and it only supports one domain.
I'm going to switch to open id instead.