In L3 i managed to make a module system where i was able to install/uninstall modules from an admin area.
if(!Bundle::exists($name))
{
// Load the bundle
// If a routes file exists then we'll assume it handles routes of it's own name.
// Remember, if you need it to handle a custom route you should manually add
// the bundle in application/bundles.php.
Bundle::register($name, array(
'handles' => File::exists($path.DS.'routes.php') ? $name : null,
'location' => 'path: '.$path,
'auto' => true)
);
// autobundle is already in the loop that's starting bundles so we
// can't let the normal mechanism start it. We'll start it here.
Bundle::start($name);
}
How i can do it in L4? L4 it looks very different for me, i started using L3 2 months ago (first framework)
Or if you still want modules that are more app specific you can check out my tutorial at: http://creolab.hr/2013/05/modules-in-laravel-4/
I'll expand on that article soon to explain how to build a simple interface to activate/deactivate these modules.
Bundles are now Packages, which are actually libraries of reusable PHP code stored on various locations and indexed by Packagist (installable with Composer).
In order to do Laravel based package development you'll need to checkout this documentation: http://laravel.com/docs/packages which should help you out.
Related
With Zend Framework 2, is there a built in means to load certain modules if certain route conditions are met?
Here's a really bad example. Imagine a Login and Registration page were built as separate modules, one would know that the Login module needn't be instantiated with /register is the present route.
If you can look past my horrible example, I think the logic is sound… Some modules provide a breath of listeners and triggers that simply aren't used unless their route is at play. Trying to avoid the bootstrap overhead where possible on a site that serves thousands per minute.
Thought I'd ask around before I roll some means to do it.
Thanks!
Hopefully this isn't too late. I needed to solve a similar problem where I wanted to load the Cli module only when working from cli. This is what I do in my application.config.php file
return call_user_func(function() {
$modules = array(
'Application',
);
if (\Zend\Console\Console::isConsole()) {
$modules[] = 'Cli';
} else {
$modules[] = 'Api';
$modules[] = 'Mobile';
}
return array(
'modules' => $modules,
// Other application config options
);
});
Typically this file would have had "return array(/* ... */);" but by making it into a function, you can apply any logic you like.
Whilst it may be possible to conditionally load modules, it won't be based on a route, as all the application routes live in modules. How would ZF2 know which modules might have routes with 'module loading' conditions attached without loading them first?
The module bootstrap overhead in ZF2 is pretty low. This is an area that was improved considerably over ZF1. It's unlikely that this will be a bottleneck for your application, so don't try and solve a problem unless you know it exists.
I'm pretty new to Laravel, I've spent some time reading about it and doing some tutorials. Lately, I've been following this tutorial about creating an authentication bundle:
http://net.tutsplus.com/tutorials/php/build-your-first-admin-bundle-for-laravel/
Basically, it's creating a simple custom auth driver extending the default auth one. Everything works quite nicely.. inside the bundle. My problem is more about how to use/access this admin/login bundle in my main application. I feel a bit ashamed asking this, I guess it has something to do with loading/starting the admin bundle in my application controller(s), but i can't get it to work.
Thank you
You have a couple of options, you can either start the bundle manually from within your application controllers each time by calling:
Bundle::start("<Your Bundle Name>");
Or when you register the bundle with Laravel (when you add it to /application/bundles.php) you can also choose to autoload it:
return array(
// ... other bundles
"<Your Bundle Name>" => array("auto" => true),
);
From looking at the tutorial this might look something like:
'admin' => array('handles' => 'admin', 'auto' => true)
Once you have either started the bundle manually, or autoloaded it, you can then call the bundle classes directly (make sure you use the proper namespace when calling the class).
You can also check out Laravel's documentation.
My website is divided into separate modules. Every module has it's own specific css or js files in /protected/modules/my_module/assets/css or js for js files. Yiis assets manager creates folder when I first use page that uses my assets.
Unfortunately if I change sth in my files - Yii does not reload my css or js file. I have to manually delete /projects/assets folder. It is really annoying when you are developing the app.
Is there a way to force Yii to reload assets every request?
In components/Controller.php add the following (or adjust an existing beforeAction):
protected function beforeAction($action){
if(defined('YII_DEBUG') && YII_DEBUG){
Yii::app()->assetManager->forceCopy = true;
}
return parent::beforeAction($action);
}
What this does it that before any actions are started, the application will check to see if you are in debug mode, and if so, will set the asset manager to forcibly recopy all the assets on every page load.
See: http://www.yiiframework.com/doc/api/1.1/CAssetManager#forceCopy-detail
I have not tested this, but based on the documentation I believe it should work fine.
Note: The placement of this code within beforeAction is just an example of where to put it. You simply need to set the forceCopy property to true before any calls to publish(), and placing it in beforeAction should accomplish that goal.
If you're using Yii2 there is a much simpler solution through configuration.
Add the following to your 'config/web.php':
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
// ...
$config['components']['assetManager']['forceCopy'] = true;
}
This forces the AssetManager to copy all folders on each run.
An alternatively solution is to publish your module assets like this:
Yii::app()->assetManager->publish($path, false, -1, YII_DEBUG);
The fourth parameter enforces a copy of your assets, even if they where already published.
See the manual on publish() for details.
Re-publishing assets on every request potentially takes a lot of resources and is unnessecary for development.
For development, it's much easier to use the linkAssets feature of
CClientScript. Assets are published as symbolic link directories, and
never have to be regenerated. See:
http://www.yiiframework.com/doc/api/1.1/CAssetManager#linkAssets-detail
For staging/production, you should make clearing the assets/ folder
part of your update routine/script.
Only fall back to one of the other solutions if for some reason you cannot use symbolic links on your development machine (not very likely).
In YII 1 in config we have:
'components'=> [
...
'assetManager' => array(
'forceCopy' => YII_DEBUG,
...
)
...
]
Im using CI-HMVC stock.
Id like to have a module structure like this:
application
modules
userabc
moduleA
controllers
models
views
moduleB
...
userDEF
moduleC
...
Is this an incorrect way of module organization? Is there another common way of doing something like this?
Im wanting to seperate the users module folders and use them in a URL like this:
userABC.domain.com/module/controller/method
userBCD.domain.com/module/controller/method
You can use that structure if you want, but keep in mind the following:
You must define each user's directory as a module location:
// application/config/config.php
$config['modules_locations'] = array(
// Absolute path // Relative from default application dir
APPPATH.'modules/userABC/' => '../modules/userABC/',
APPPATH.'modules/userDEF/' => '../modules/userDEF/',
APPPATH.'modules/userGHI/' => '../modules/userGHI/',
// etc.
);
You might be able to do this dynamically, but remember that config.php is loaded pretty early so you may need a pre_system hook.
The other thing, which is important if you want all users' modules accessible regardless of which subdomain is active: Order matters!
If userA has a module called "blog" and so does userB, only userA's will ever get loaded (assuming you define userA's module path first). If you're certain no two modules will share the same name, this won't matter as much, but you may suffer a performance hit as the loader will go through the whole stack of module locations until it finds the requested one.
It sounds like you should define a single module_location depending on what user's site is loaded (the subdomain). Something like:
// Get this value dynamically (not sure how you need to do it)
$current_user = 'userABC';
$config['modules_locations'] = array(
APPPATH.'modules/'.$current_user.'/' => '../modules/'.$current_user.'/'
);
Adding submodules in codeigniter you need to defile moudules direcotry in config file like this.
$config['modules_locations'] = array(
APPPATH.'modules/' => '../modules/backend/',
APPPATH.'modules/frontend/' => '../modules/frontend/',
);
Starting from the skeleton application using beta3 how would you resolve the view path for a new module called Foo?
I have added below to the di config and now both modules action's render Foo's views.
'Zend\View\Resolver\TemplatePathStack' => array(
'parameters' => array(
'paths' => array(
'foo' => __DIR__ . '/../view',
),
),
),
I would expect Application\Controller\IndexController::indexAction() to render the views in Application and for Foo\Controller\IndexController::indexAction() to render Foo's views.
Note that questions like this help shape the direction of the stable framework. :)
One idea I've been toying with is to use the module as part of the view script resolution. Right now, the default used is "/"; my proposal is to use "//", as this would help prevent naming conflicts between modules; it also makes it much simpler to understand exactly what view script you are overriding if you use template maps.
You can use this approach today, but it will require manually setting the template on the view models you return from your controllers.
This doesn't currently work in ZF2 as there is no concept of taking the namespace into account when resolving view scripts. Discussions are currently ongoing on how best to tackle this.
For the time being, you have to name each controller differently. In general, we are recommending that you name the "primary" controller within a module after the module name. That is, the primary controller in the Foo module would be FooController.
You actually can do this; and it is not too bad....
Rob Allen himself had a blog post that basically makes this work... Notice you have to basically handle it as a module based loader that separates much of the work out so that we don't have controllers utilizing it: http://pastie.org/3824571