YII on different domain - php

I have two part of application. The first is a manager panel and it is pointed to http://mysite.com/. Other is a personal product page and they are pointed to own domein http://product_domain.com/ . These are parts have two different router maps but common models, components and widgets. The list of all product domain I have saved in database.
What the best way to separate this parts?
P.S. Maybe i should have two different application or config?

What we usually do is use a combination of a "prerouter" and modile.
Yii supports this by way of an "onbeginrequest" => array('Class', 'function') in your config.
In that function you can detect where the user came from and make the needed changes. For example activate a specific module (if all the functionality is grouped in one), or set a different defaultController. Perhaps you want to load a custom theme?
You can do it all in there before anything is done.

Related

Loading libraries depending on different country - codeigniter (architectural issue)

My application is scaling to multiple countries and controller the users flow is getting hard. The application is built on codeigniter.
I have a Mothercontroller which calls child controller to redirect users to the right path depending on the country.
What I would like to do is load different libraries and use functionality depending on the country.
For example, If I have a library called register_fin that has functions to register a user for Finland and also a library called register_den for Dannish user.
I am trying to figure out a way to load different libraries depending on the users path .
The problem is that I don't want to do if (country ==x) {load library} which will cause a huge if else issue if there are lets say 20 libraries to load.
I was wondering if the parent controller can judge and preload the library from child controller but what I noticed is that when i move to a different controller the library function is not used.
Is there a way to build a controller that can also load libraries depending on the users countries or is there an better alternative to this?
Any advice would be great.

Change templates/views location in Symfony2

I will be working on project that has different theme for each domain (same application will be serving multiple domains).
I need to change location of templates completely outside the application folder, possible on another volume
I need to make it work with multiple domains with multiple themes - i guess theres cache problem
S how to do this stuff with Symfony2 and twig?
EDIT: I will try to ask this: What or where do I need to rewrite to get custom logic on locating specific templates that symfony uses to render pages.
I can't say if first point of your question is a bad practice (and don't know even if it possible, but I would say yes).
However, what I would do is some kind of "manager" that will takes responsibility for choosing what kind of template render, based onto your own logic. Some kind of "intermediate level" between actions and views.
You could create it as a service and use everywhere, without have need to instantiate it every time.
It could read a file for configuration or, even (but less springy), use a class-internal configuration.
Algorithm could be something like this:
Take into account your request
"Eat" data and "spit out" the correct template (name)
Pass template (name) to your view
Extend (dinamically) the template given by your manager
Please, don't ask me some code because it could result in some hundred lines :)

How to use one module with distinct configurations?

So I am using the latestnews_modules in joomla, and I am rendering latest_news at the footer of the site, but also I need to render at the right other latest_news, but I see only one view default.php, how can I make that one module works different in each position???
if I create another module like the previous, they bot have the same behavior, how can this be solved, help!!
There should be configurable settings for the module:
Go to the module you wish to change
Look on the right; you should see a 'panel' headed 'Parameters'
You can set things such as the total count, the section/category to pull articles from, authors to include, and the order.
If your requirements are different from that offered by the module, you'll need to either create your own custom extension, or find a third-party extension that does what you want.
What are you trying to achieve?
a) If you want different "behaviour", i.e. different functionality you need two different modules and in that case would need to clone the latestnews module with your modifications. By the way, if you are modifying the code of core modules you really should do this using template overrides in case you end up losing your changes after a security patch - unlikely for this module, but possible.
b) If you want the same behaviour with different parameters do as Bobby Jack says and change the settings for one of the modules by going to the Module Manager, selecting the module and changing it's settings, e.g. how many items to display and from what category.
c) If you want different styling for the two modules use the Module Class Suffix to change the class attribute of one of the modules and write CSS to override the display of the relevant module instance.

Reusing forms and controllers in Codeigniter

I'm learning the OO and MVC paradigm (using Codeigniter and PHP). I continue to find warnings such as this: If you find yourself pasting the same code into multiple files, then you aren't using OO/MVC properly. So, here's a question for more experienced programmers.
I have a create-user form that I am using two very similar versions of:
Version 1 (at /volunteer/register) is created by an anonymous user. The form lives in the volunteers controller, and needs to be verified by an admin.
Version 2 (at /admin/create_volunteer) is created by a logged-in admin. The form and validation is nearly the same, but it is submitted with different parameters.
Another, similar example:
I want to build different user dashboards that share a template, but will be used by different user roles and have different functions and information based on role. As I see it my choices are:
Create a Dashboard controller with three functions defining the data loaded into the dashboard template.
Add the a dashboard function to each role's controller (Volunteer, Admin etc).
Create a controller for each case (Volunteer, Admin, etc.)
I apologize if this appears sophomoric but essentially I'm looking for rules-of-thumb to determine how to design architecture in MVC.
My questions:
In the first example, is my logical choice of controllers (Volunteer & Admin) less than ideal? Is code replication in this case an acceptable practice?
Can anyone recommend architecting tools to establish logical consistency and good workflow for MVC?
Especially since the two forms are not the same (different rules, different interface) there's absolutely nothing wrong having two separate view files if you need it. Loading the same view file in two different controllers or methods is perfectly acceptable, indeed it's appropriate. If there are only a few tweaks that need to be made, try to reuse the view file by passing different data to it.
If you want to simply load the form view file in different instances, that would save you some code duplication. Just set different rules and if needed, pass different data to the view. It's similar to using the same form to create and edit something in two different methods. If the output is going to be totally different, just write separate view files. If it's the same output but with different data - definitely reuse it.
Don't get obsessed with trying to not duplicate view fragment code - if you are writing even more code to force the reuse of a view file by modifying it for different instances, it kind of defeats the purpose. Try to just make it a general practice to make your code as reusable as possible.
So, without seeing your actual code - I'd say don't worry about it. In my experience, view files for front-end and back-end are almost always unique (completely different UI). In general, if you find you are duplicating the same very similar code a lot, it's time to write a function, class, or template for it.
It seems you would like to use some ACL for distinction between roles (Volunteer and Admin) that will check whether requested module or action can be accessed.
Creating different controllers for the roles doesn't seem to be a good choice since this architecture could not be reused - you don't want to reuse specific Admin or Volunteer functions in other applications but rather a module that lets you create and control such roles.
You would like to reuse a code offering particular functionality, this might be one controller, one model and some view files.
Most programmers consider duplicated code as a sign that the solution to a problem still can be improved.
If the problem in your case is that the from is defined in one controller but you need to use it in another controller as well, then you need a better place to define the form so that both controllers have access to it independently from each other.
Make the form configurable so it's possible to reuse it.

kohana v3: using different templates for different subdomains

I have a kohana v3 app. 2 subdomains pointing to this app. what I have to setup that kohana uses a different template if the app called with subdomain2.example.com?
at the moment all calls (from subdomain1 and subdomain2) use the standard template: 'templates/default'
thank you!
daniel
First, get the subdomain name from $_SERVER['SERVER_NAME']:
list($subdomain) = explode('.', $_SERVER['SERVER_NAME'], 2);
Then choose what template to use based on the subdomain:
// Replace this with a switch() statement if you want to choose another way
$this->template = 'templates/'.$subdomain;
The above code should be placed in the Controller::before() method before you call parent::before(). This assumes that you are using the Controller_Template or an extension of it.
may anybody can help me: kohana v3: using different templates for different subdomains
danzzz, there are a few ways... (i dont have time to go into detail.. so i'll give a quick go here..) .. A) use URL rewriting to map bla.site.com to site.com/bla (and www.bla.com+bla.com to bla.com/www) ... use that first param as the trigger... then load a different module at the top of the stack so it can override anything from a lower module - this assumes anything that is overridable is kept in a module, otherwise, you can use it as a trigger any
where in the code...
and B) is really the same thing, but using that param as the view name or similar...
whenever i have something like that, i tend to leave my application folder empty, and have an application module near the top of the module stack.. that way, i can load a "skin" module higher up and have the cascading FS do all the hard work...
keep in mind that "skin" modules etc will need a strict set of rules and interfaces, if you make a change to the app, you need to know all the skins still work...

Categories