I'm building a folder structure and global configuration to allow me to create applications on Yii framework where all applications could share common codes, extensions or modules.
The idea is, each application would have the business level for that application, but, everything that can be shared between applications, we want to use as a common repository (models, extensions, widgets, etc)
For example, we want to share the Auth extension to control the system permission, but I want to 'install' Auth under the common folder instead under each application.
Below, the architecture that I would like to build:
I found the YiiBoilerplate as something similar, but they don'y configure Yii in such way that we want to.
The folder structure desire is:
common/
css/
images/
protected/
commands/
components/
config/
controllers/
extensions/
models/
views/
Application1/
css/
images/
protected/
commands/
components/
config/
controllers/
extensions/
models/
views/
So, let's go for some points:
If my user is under the application X (www.applicationx.com) and the login page is a 'common' structure I want to display to user something like this: www.applicationx.com/index.php?r=user/login.
I want to be able to 'navigate' between the application folder and the common folder easily.
I do not want to use Theme because I have different applications with different visual requirements and behaviors.
Any thoughts about this? Any good advices? Thanks in advance!
Well, I found some way of how to do it.
First of all, my folders structure, looks similar as it:
common/
css/
images/
js/
extensions/
bootstrap/
auth/
protected/
/* Yii Default directory folder*/
Application1/
css/
images/
js/
protected/
/* Yii Default directory folder*/
Config File Under Common Folder
return array(
'import'=>array(
'common.components.*',
'common.models.*',
),
'modules' => array(
'auth',
),
'components' => array(
'authManager' => array(
'behaviors' => array(
'auth' => array(
'class' => 'common.modules.auth.components.AuthBehavior',
'admins'=>array('admin', 'foo', 'bar'),
),
),
),
'user' => array(
'class' => 'common.modules.auth.components.AuthWebUser',
),
'bootstrap'=>array(
'class'=>'common2.extensions.bootstrap.components.Bootstrap',
),
),
);
Login
The login is under 'common', so, to redirect to the login page, I just call the SiteController.php and I implented there the login process, giving for the user the ability to select the application that he wants to get in.
After the login, I redirect the user to the application address:
$this->redirect(Yii::app()->request->getBaseUrl(true) . "/../" .$App. "/" . "");
Config File Under Application Folder
under the application, the index.php file has the alias for the common directory, is the way that they can still 'talking'.
Yii::setPathOfAlias('common', dirname(__FILE__) . $directory);
If you want to do something similar and are finding hard to understand, let me know, I will put here more information, if you need to.
Related
I have 2 websites projects on the main directory inside /var/www/ directory
what I want to do is creating controller with it's views to be shared between the 2 project, not repeat the same controller on both projects,
now I create it ex. myController.php inside host A
How can I access the controller from the second host B ?
and render myaction function?
the url rules in the main.php config file
'newpage/list'=>'myController/myaction',
Edit :: I'm using this advanced template
**DIRECTORY STRUCTURE**
common
config/ contains shared configurations
mail/ contains view files for e-mails
models/ contains model classes used in both backend and frontend
tests/ contains tests for common classes
console
config/ contains console configurations
controllers/ contains console controllers (commands)
migrations/ contains database migrations
models/ contains console-specific model classes
runtime/ contains files generated during runtime
backend
assets/ contains application assets such as JavaScript and CSS
config/ contains backend configurations
controllers/ contains Web controller classes
models/ contains backend-specific model classes
runtime/ contains files generated during runtime
tests/ contains tests for backend application
views/ contains view files for the Web application
web/ contains the entry script and Web resources
frontend
assets/ contains application assets such as JavaScript and CSS
config/ contains frontend configurations
controllers/ contains Web controller classes
models/ contains frontend-specific model classes
runtime/ contains files generated during runtime
tests/ contains tests for frontend application
views/ contains view files for the Web application
web/ contains the entry script and Web resources
widgets/ contains frontend widgets
vendor/ contains dependent 3rd-party packages
environments/ contains environment-based overrides
Question is : How I can access the front end controllers in front end directory from backend rules ?
Frontend and Backed are two different modules. When they are bootstrapping from index.php they behave like two individual projects. So, you cannot route from frontend to backed or vise versa using urlManager of Yii.
May be you can maintain some params in common/params where you can configure absolute Url.
Actually you can reuse frontend controller classes in backend - you can use controllerMap property of application or module to define custom controller classes. For example if you add something like this to your backend config:
'controllerMap' => [
'mycontroller' => 'frontend\controllers\SomeController',
],
Then frontend\controllers\SomeController will act like it would be backend\controllers\MycontrollerController - backend.local/mycontroller will use the same controller as frontend.local/some, but with different contexts (and probably layouts).
You can even use controllerNamespace to load all controllers from given namespace. For example create separate module in backend:
namespace backend\modules;
class FrontendModule extends \yii\base\Module {
public $controllerNamespace = 'frontend\controllers';
}
Then this module will use all frontend controllers at backend context. backend.local/frontend/some will use frontend\controllers\SomeController.
I'm about to start development of a site using Laravel4 that will include a cms hosted on a sub-domain. What I want to know if is there is a way to have the main Laravel installation shared between the two apps?
I've had various success in testing using the following example: Laravel full URL routing, however I want to keep the functionality from the app folder separate and have something like say, app_main, app_cms that holds the relevant models, views and controllers for each site in there.
There doesn't seem to be much help that I can find in how to set up Laravel for such a requirement, so any help on this would be great.
I have a multihosting solution, which after logging into FTP contains this folders:
domaina.com
domainb.com
domainc.com
If I'd like to share same Laravel code between those websites,
I just create 'Laravel' folder on the same level, so it looks just like this:
domaina.com
domainb.com
domainc.com
laravel
This 'laravel' folder holds everything except 'app' & 'public' directory.
I just place content of 'public' directory right inside 'domaina.com' folder (for example).
Open up 'index.php' and adjust these lines to match actual location.
Now you are good to go
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
bootstrap/paths.php holds the main folder definitions. For each instance, you can alter the app folder, public folder, base folder, storage folder and so on from the file.
You can set a cookie/session, or check domain etc. for main and subdomain and alter it like:
'app' => Session::has('subdomain')?'../../app':__DIR__.'/../app',
use Router for this.
e.g.
Route::group(array('domain'=>'example.com'), function(){
//Define the routes for example.com
});
Route::group(array('domain'=>'cms.example.com'), function(){
//Define the routes for cms.example.com
});
for easier maintanace, you can use namespace for controllers.
e.g. your controller folder can look like this
App
|
|---Controllers
|-- site
|
|-----HomeController.php
|-- subdomain
|
|-----HomeController.php
now, for site controllers, use a namspace like, <?php namespace site;?>
for subdomain controllers, use a namespace like <?php namespace subdomain;?>
in the routes file, define the routes as,
Route::group(array('domain'=>'example.com'), function(){
Route::get('/', array(
'as' => 'index',
'uses' => '\site\HomeController#index'
))
});
for subdomains,
Route::group(array('domain'=>'cms.example.com'), function(){
Route::get('/', array(
'as' => 'cms.index',
'uses' => '\subdomain\HomeController#index'
))
});
plain and simplest way.
I'm working on multi-website CMS in Zend Framework.
I've came to a point where I need to override module from application/ folder in my website/application folder.
A bit better explanation of my issue:
Here's tree of my application (important part):
library/
application/
module1/
controllers/
models/
....
module2/
controllers/
models/
....
websites/
website1.com/
application/
module1/
controllers/
models/
....
So what I need to do is that module1/ in websites/website1.com/application/ override module1/ in application, IF it exists. I want everything in module1/ in websites folder to override everything in main application folder.
I'd also like if there are 2 controllers in this module1 (for example IndexController and TestController) and if I put only TestController in websites folder under module1/controllers to override ONLY TestController from Application folder and to get IndexController from main folder.
Sorry if I failed to explain exactly what I'm trying to achieve. If there's something unclear, please ask.
Thank you.
Edit:
Okey, first of all - thanks for your comments.
Reason for having websites/ folder is, mostly because of vhost as I prefer that all of my websites have separate (public?) folders, and reason for having one library with application folder is because, obviously, upgrade reasons (so when I, for example, upgrade Zend - I don't need to upgrade it for every website).
I'll most likely rarely use overriding option for controllers, and yes, I'd even prefer if I could, for example, extend main Controller (for example - IndexController) and override some functions, but I thought that's way harder then override whole class.
Here's full structure of my application:
library/ - Library folder contains Zend and many other classes that I'll use in my application.
Zend - Zend Framework
MyCMS - Classes from my old CMS.
sites/ - Folder that contains websties.
website_1 - Website one.
application/ - Application folder for website one. If I need to redefine module or something. So, if I need to override module: main_module, I'll create folder main_module here with files that I want to override.
config/ - Configuration for website_1 - if I need to override, for example, application.ini
lang/ - Language files for this specific website.
templates/ - Templates folder for website (layouts and templates). By the way, I'm using smarty.
default/ - Main template.
layout/ - Layouts for Zend View.
css/
js/
images/
modules/
files/ - Place to upload files in, for this website. This will contain user avatars and stuff.
index.php - Main file that runs bootstrap and application.
Bootstrap.php - Inherited bootstrap. In case I need to override some functions from default bootstrap.
application/ - Main folder that contains application modules and stuff.
main_module/
configs/ - Module configuration.
config.ini
controllers/ - Controllers for this module.
modules/ - Submodules. There are like boxes that I display on website. For example, if my main module is "news", here, I'll make new sub-module to display box with statistics.
submodule/
services/ - XML/JSON/whatever service. If someone targets controller in services with specific parametars, it'll return response in requested format.
controllers/ - Services will only have controllers.
configs/ - Configuration for this submodule.
controllers/ - Controllers for this submodule.
models/ - Models for this submodule.
lang/ - Language files for this submodule.
template/ - Templates for this submodule.
helpers/
css/
js/
images/
index.html
models/ - Models for main module.
lang/
services/ - Main module will also have services. See submodule services for explanation.
controllers/
template/
helpers/
css/
js/
images/
index.html
Bootstrap.php - This is main bootstrap file that every website's bootstrap file will extend (and override some methods - if needed).
Update
Even though I highly discourage your directory structure, it's your application and you should structure it however you like.
To load multiple controllers, you should create a Front Controller Plugin to add paths to the controller directories stack
class My_Controller_Plugin_Paths extends Zend_Controller_Plugin_Abstract
{
public function preDispatch()
{
// Something like this...
// Would be best to load paths via config/database or somewhere
$dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();
$dispatcher->addControllerDirectory('/path/to/website1.com/controllers')
->addControllerDirectory('/path/to/website2.com/controllers');
}
}
This is entirely untested, but you get the idea. Just make sure you register the plugin with the Front Controller in you bootstrap
I'd agree with #Laykes. This is a badly structured application.
I'm not sure of your exact requirements, but if it were my application, I would try to structure it like this:
/application
/modules
/default
/controllers
/IntexController.php // Default_IndexController
/Website1com
/IndexController.php // Default_Website1com_IndexController (possibly extends Default_IndexController)
Here you can see a properly structured class inheritance without creating totally separate, and probably duplicate, application folder.
Autoloading anything like this though totally depends on you and your priorities. You could do a number of things, each with their own +ve's and -ve's.
You could throw all paths into your include_paths in the order you want
Check files exist and load from a front controller plugin
To name a couple.
I have all my zend applications like this
/app/
/app/registration
/app/games
I need to create a URL for games like this
mydomain.com/games/game-1
How do I set up the controllers and views in this directory structure when its like a module or sub application?
/app/games
/app/games/configs
/app/games/controllers
/app/games/controllers/Game1Controller.php
/app/games/views
...
One way would be to use the existing module conventions:
application/
controllers/
views/
configs/
modules/
registration/
controllers/
views/
configs/
The good thing about this is that ZF is already set up to handle this to some extent by convention... If you do it another way you are going to have to modify things more.
In this layout the top level controllers, views, etc.. are the Default module, while all other modules are under the modules directory.
I would also make each game its own module. If you have common code used in all games make classes you can extend and put those in your library.
You can also use zf tool zf.sh create module yourModuleName to create the default directory structure for modules.
Hey all, kind of new at Kohana and I have a quick question.
I have a site where there will be three subsections, organized by subdomain (i.e. admin.site.com, community.site.com, www.site.com) but each of the subsections will be pulling from the same database so should be sharing the same models. Is there a way to organize it so that I can use the same Kohana model/system/module files for each of the subdomains, but keep the application folder separate? Something like:
/home/user/admin/
application/
bootstrap.php
cache/
...
index.php
/home/user/community/
application/
bootstrap.php
cache/
...
index.php
/home/user/public_html/
application/
bootstrap.php
cache/
...
index.php
/home/user/kohana/
modules/
...
models/
...
system/
That way I can keep Kohana up-to-date across three sites with only one update, plus I can use the same modules and model classes. Is there any way I can make this happen? Or is there some other method I should be using?
Thanks!
I figured out how to do this, so I thought I would answer it in case someone else needs to know.
I moved my system and modules folders out of the webroot (to /home/user/kohana/) and created a folder there called sites. Then I created three separate folders in /home/user/kohana/sites/ for each of my three subdomains (admin, community, and www). I copied the contents of the application folder to each of these folders, then copied the index.php and .htaccess files to the webroots for each subdomain.
In each of the index.php files, at the top, I added:
$install_dir = '../kohana/';
and edited the following directory variables to include the new path:
...
$application = $install_dir.'sites/admin';
...
$modules = $install_dir.'modules';
...
$system = $install_dir.'system';
And it worked! I feel kind of stupid for not realizing how easy it was to move the directories around. Hopefully my explanation is coherent and assists someone else in the future.