I'm trying to switch to ZF2 from ZF1. From what I've read about the new Zend\MVC\Router and the way it is configured, it looks like every single location should be described in ['router']['routes'] config key.
Is that really so? In ZF1 you could build a complex app with multiple locations and not have a single route described. I find it hard to believe, hopefully I am missing something.
Thanks!
The routing works in a similar way to ZF1. The config in the skeleton app includes a few example routes, one of which is a /:controller/:action route (line 42). So this is your out-of-the-box ZF1 style MVC route.
In ZF1, the framework adds a /:controller/:action and /:module/:controller/:action route for you (which you had to remove if you had some custom requirements). In ZF2 you have to define the routes yourself, but if you want the same setup as ZF1, the skeleton app setup works in the same way, just without the module prefix.
Related
I'm building an application using Durandal 2. I want to define multiple routes using the same VM/View for different context.
Exemple :
/sectionA/:id/home using module ID /viewmodels/home
/sectionB/:id/home using module ID /viewmodels/home too
At first, sectionA and sectionB are meant to use the exact same VM and Views. But, eventually, they will be different. This is not where the issue is since when they'll be different, they'll have their very own VM and shared views (using MVC partials) which will work straight out the box.
The point is, for as long as the page are the same, we don't want to duplicate the VM and Views, generating a lot of garbage for nothing.
I tried the example shown above but that doesn't seems to be possible to do this. Whether the routes are different, it seems that the router cannot make the difference between the two routes and just throw a "route not found" exception although the route is defined in our route definition file.
So the question, is it possible to define two route, with obviously different routes definitions, but using the same moduleId?
If more details are require, don't hesitate to ask for clarifications.
Thanks! :)
How can I manipulate other modules without editing them ? very the same thing that wordpress modules do .
They add functionality to core system without changing the core code and they work together like a charm.
I always wanted to know how to implement this in my own modular application
A long time ago I wrote the blog post "Use 3rd party modules in Zend Framework 2" specifically about extending Zend Framework 2 modules. The answer from Bez is technically correct, it could be a bit more specific about the framework.
Read the full post at https://juriansluiman.nl/article/117/use-3rd-party-modules-in-zend-framework-2, but it gives you a clue about:
Changing a route from a module (say, you want to have the url /account/login instead of /user/login)
Overriding a view script, so you can completely modify the page's rendering
Changing a form object, so you could add new form fields or mark some required field as not required anymore.
This is a long topic, but here is a short gist.
Extensibility in Zend Framework 2 heavily relies on the premise that components can be interchanged, added, and/or substituted.
Read up on SOLID principles: http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
Modules typically consists of objects working together as a well-oiled machinery, designed to accomplish one thing or a bunch of related things, whatever that may be. These objects are called services, and managed by the service locator/service manager.
A big part of making your module truly extensible is to expect your developers to extend a class or implement a certain interface, which the developer register as services. You should provide a mode of definition wherein the developers can specify which things he wants to substitute, and/or add their own services to -- and this is where the application configuration comes in.
Given the application configuration, you should construct your machinery a.k.a. module services according to options the developer has specified i.e., use the developer defined Foo\Bar\UserService service as the YourModule\UserServiceInterface within your module, etc. (This is usually delegated to service factories, which has the opportunity to read the application configuration, and constructs the appropriate object given a particular set of configuration values.)
EDIT:
To add, a lot can be accomplished by leveraging Zend's Zend\EventManager component. This allows you to give developers the freedom to hook and listen to certain operations of your module and act accordingly (See: http://en.wikipedia.org/wiki/Observer_pattern)
I'm in the middle of converting an existing app built on top of zend framework to work as a plugin within wordpress as opposed to the standalone application it currently is.
I've never really used zend so I've had to learn about it in order to know where to begin. I must say that at first I didn't think much of zend, but it's funny because the more I understand how it works the more I keep questioning why I'd want to remove dependency when it's a clearly well thought out framework. Then I'm reminded that it's because of wordpress.
Now I already know there are WP plugins to make zend play nice with WP. In fact I'm aleady using a zend framework plugin just to get the app functional within the WP admin area which is allowing me to review code, modify code, refresh the browser, review changes, debug code, again and again.
Anyway, I really don't have a specific question but instead I'm looking for advice from any zend masters out there to offer advice on how to best go about a task like this one.... so any comments, advice, examples or suggestions would be super.
One area I'm a little stuck on is converting parts of zend->db calls to work as wpdb calls instead... specifically the zend->db->select.... not sure what to do with that one.
Also on how to handle all the URL routing with automatic calls to "whatverAction" within thier respective controllers files.
Any help would be great! Thanks
You're probably facing an uphill battle trying to get some of the more major components of ZF to work in harmony with Wordpress. It sounds like you've got a full MVC app that you're trying to integrate into a second app that has very different architecture.
You probably want to think about which components handle which responsibilities. Wordpress has it's own routing and controller system that revolves around posts, pages and 'The Loop'. This is entirely different from Zend's Action Controllers and routing system.
It's possible you could write a WP hook to evaluate every incoming request and decide if it should be handled by WP or a ZF controller. However, it is doubtful you would be able to replace WP's routing system outright with ZF's or vice versa.
Same idea, where Zend_Db is concerned. There's nothing stopping you from using Zend_Db to access Wordpress's database, but trying to somehow convert or adapt Zend_db calls into wpdb calls sounds painful. If you have a large model layer, you probably want to hang on to it, and find a way to translate data from those models into the posts/pages conventions that Wordpress uses.
Personally, I would use ZF to build a robust business layer that can be queried through an object model via a Wordpress plugin, and then rely on Wordpress to do the routing and handle the views.
Zend_DB_Select is simple SQL query (but created using objects) that can be used like any other query. Just turn it into string. Ex.:
mysql_query((string)$zendDbSelectObject);
To use your own ModelMetadataProvider you normally set it in the global.asax.
I'm using MVC Turbine and I need to inject a dependency into my ModelMetadataProvider as well.
Something like this:
ModelMetadataProviders.Current = new MyModelMetadataProvider(ISomeDependency);
How is this best accomplished with MVC Turbine?
The best place to put these pieces is to override the Startup method within your web application (the type that inherits from TurbineApplication). We're currently working on making these MVC2 features easier in v2.2 by introducing a ModelMetadataBlade that will do all the wiring up for you to the ModelMetadataProvider.Current property.
So all you'll have to do is register MyModelMetadataProvider with the container like so
container.Register<ModelMetadataProvider, MyModelMetadataProvider>()
then MVC Turbine will do the rest for you. To get an idea of what I'm talking about, checkout the way we're wiring up ModelValidatorProviders. The ModelValidatorBlade asks the ServiceLocator for all the registered ModelValidatorProvider and wires them up with the runtime.
If you have any feedback or ideas, could you post them to the Google Group? Trying to keep these things organized :)
Thanks!
I have the following bit of registration code:
Component.For<IPublishingService>().ImplementedBy<UseStoredProcedureToPrintService>(),
Component.For<IConfirmationDialog<AutomatedTransaction>>().ImplementedBy<ShipmentConfirmationDialog>().Named("ShipmentConfirmationDialog"),
Component.For<IConfirmationService<AutomatedTransaction>>().ImplementedBy<SingleTransactionConfirmation>().ServiceOverrides(
ServiceOverride.ForKey("shipmentDialog").Eq("ShipmentConfirmationDialog") ),
A requirement came down the line that in some instances the application is supposed to behave somewhat differently. Great I thought, this is exactly what I was using Castle Windsor for to begin with.
So I wrote my new components and I register them first. For example, I implement IPublishingService differently and register the new implementation first so that it is resolved over the default one above. However, a problem occurrs in the few cases where I had no choice but to use an id to wire up my service overrides. For example how do I redirect the ServiceOverride for ShipmentConfirmationDialog to use my new SpecialCaseShipmentConfirmationDialog implementation without modifying the bit of code above?
There are all sorts of mechanisms in castle windsor that I don't really understand like forwarding and ActAs that I'm hoping will provide a simple answer.
I'd keep it simple. If it's configurable, put it in the config (web.config / app.config) then just load the ID using ConfigurationManager.AppSettings["shipmentDialogToUse"];
Also remember that the fluent registration API is not the be-all and end-all of registration. XML still has its time and place where it's the right tool for the job.