I will be shifting my code base to the new 2.0 framework and just had a few questions on the following points
My urls will be as follows
example.in/city1
example.in/city1/admin
example.in/city2
example.in/city2/admin
I would like to know what would be the best way to switch the database based on the city in the url? .
In my webroot i will have directories like city1, city2 each containing an index.php file which points to the single code base.
Now i only need a way to switch the database based on the url entered.
Regards,
Sheldon
I completely agree with #poelinca and #Ross, you should definitely consider rethinking your design.
however for reference issues this topic was already covered in the CodeIgniter forums pretty well over here
Basically you just configure another set of $db items per connection and then request the connection based on those configuration parameters by the CodeIgniter framework, by providing the new $db as a parameter for the DB class constructor.
Related
A website I am currently developing with Neos / Flow includes a self-developed shop system implemented as a Flow Plugin. The products, variants and vouchers are kept as domain models.
Since the customer wants to provide their website in different languages I need to find a way to manage translations for the domain objects.
I cannot find a way which is baked into Neos/Flow so my first thought was to simply insert translation identifiers inside the translatable fields (description & stuff like that) which are then used inside the view with the translation viewhelper. This would work totally fine if the customer would not want to edit those fields by themselves.
My next idea was to just implement an extra field for each language-dimension and each translatable field (like description_en; description_es, …). But this would be the worst approach in terms of maintainability and changeability.
I usually worked on TYPO3 projects where translation of domain objects is really easy and working out of the box. So this experience inside Neos is very frustrating.
Does anybody came across a similar problem or even has found a solution to this?
whenever we've got the requirement to have multi-language content so far, we've solved that, by storing the data within the Neos Content Repository. This way language handling aka dimensions work out of the box. Also, building a UI for that records is very easy by using inline editing or the inspector of the content module.
Note, that storing data in the CR does not necessarily means, that you have to store it under the /site root node. You could also add a new root node /products to store your products.
You could have a look at https://github.com/neos/metadata-contentrepositoryadapter where meta data is stored under its own root.
Hope that helps,
Cheers, Daniel
For the record, something like that could also be achieved with the Doctrine Translateable extension in pure Flow:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md
See http://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Persistence.html#on-the-doctrine-event-system on how to activate the extension in Flow.
However, the cleaner aproach indeed is to actually separate domain model and content (unless you build a CMS and the content is your domain ;)
I have an Asp.net Core application I want to be able to allow multiple/ different Tenant(Client)to access the same application but using different url's. I have common database for all tenant(client).
So It is the main part I want to host my application in a domain say... www.myapplication.com then allow different Tenant(client) to access the same application using
1.www.TenantOne.myapplication.com
2.www.TenanatTwo.myapplication.com.
3.www.{TENANCY_NAME}.myapplication.com
I can't find any info on how to do this and I'm stuck.
How to do it? Please provide the code. Thanks.
As Saravanan suggested these types of questions don't belong here on SO. To get you started, I suggest you start looking if there are any frameworks such as SaaSKit available to add a multi tenancy layer to the pipeline.
The essential part is to know where each request comes from. Using subdomains is a good way to achieve that and middleware is a good place to 'identify' your tenant. You could have a database to persist the tenants but the implementation is entirely up to you. I also wrote a little article on the subject. Although it isn't ASP.NET Core, the principles still apply.
The approach I believe you are looking for is similar to the article at the url below.
https://dotnetthoughts.net/building-multi-tenant-web-apps-with-aspnet-core/
In it, the author splits the requesting URL into an array of strings delimited by the dot in the address. The variable 'subdomain' is then set to the first element of that array. In your question, it looks like you may want to use the second element in the array, but you get the idea.
var fullAddress = actionExecutingContext.HttpContext?.Request?
.Headers?["Host"].ToString()?.Split('.');
var subdomain = fullAddress[0];
//do something, get something, return something
How you use this data is up to you. The author of the article created a filter attribute, but there are many possibilities such as passing the tenant name as a parameter to a service function.
Sorry,you have to get something to start with and then come back for the people to help you with.
I would say that this is all of a domain based wild card mapping and change in your authentication logic to get the tenant id from the URL. Once you identified the tenant, you just login and then take it forward. Like you might be having a database with the tenant details like
tenant1 | tenant1.company.com | guid-ofthe-tenant | etc...
Once you get the URL, you lookup in the above table and get the tenant code and then you choose the login mode and then proceed.
In case you have tried something yet, we would be happy to point you if it does not work yet.
I've been reading the codeigniter manual about routing but I don't understand how to apply the feature to my situation.
I'm trying to design the following URI
example.com/shopName/product/2/description
example.com/shopName/product/2/gallery
Where shopName is the name of the shop (ie. different every time).=
I'm in the beginning of the project so my controllers are open to alterations.
I've been thinking of doing something like the structure below, as a workaround, but it is definitely not what would be ideal.
example.com/shop/pdesc/2
example.com/shop/pgallery/2
First change route like this:
$route['shopName/(:any)/(:num)/(:any)'] = 'shopname/$1/$2/$3';
You may change this as per your design.
Then create controllers. Read this guide for details. link
After reflection over Fat models and Skinny Controlers (i have adopted), my question goes to view.
It's logic that :
View read Rowset (Zend_Db_Table_Rowset), so object container, or an array of datas ?
View test with Zend_Auth if user connected and show connect or disconnect pictures, or controller test with Zend_Auth and say if user is connected (like a simple data).
View construct url to others controllers/Action, partially or totally without controller datas (plain Example : href="/users/delete/$id"), or view must create url with datas controller (ex : $urlFormat = "/users/delete/%s" and $id = x from controller, and view compose it ($id can be in array with most $id for example in list view, with links to action).
So, view has responsability to format datas, to html, or to xml, to be parsed. But where are borders responsabilities. If you have an article, i can read. Good documentation is very rare.
One more, sorry for my language, i don't write very goodly english. Thanks.
Here are the answers:
No. This should be done by the Controller which will pass the data to the view in a var(s)
No. The controller should do all the tests. The auth test is surely a part of these control
The vars/params should be tested by the controller and the url can be constructed by the view
I think you should read more about the MVC pattern (this is the pattern which has been implemented by the Zend Framework and many others). You can read about this pattern here or wherever you want.
I pretty much agree with Aurelio. However, as for documentation not being too widely available, I have to disagree. Have a look at the list below, which contain both web links and links to text references all about MVC:
Links:
MVC Pattern
Zend Framework + MVC
Zend Framework MVC Folders (ZendCasts)
Books
PHP Objects, Patterns and Practice 3rd Edition (Expert's Voice in Open Source)
Pro PHP: Patterns, Frameworks, Testing & More: Patterns, Frameworks, Testing and More
Aurelio's answered your questions I believe, but here's some extra information. The Controller determines what should happen and put look after retrieving of information from the model.
The view however, isn't concerned with where information comes from, but takes care of the formatting. It's not responsible for connecting to databases, caching records or reading configuration information. I don't mean to be condescending in what I've said and hope that it doesn't come across that way.
Based on the following example URL structure:
mysite.com/mypage.aspx?a=red&b=green&c=blue
Pages in the application use ASP.net user controls and some of these controls build a query string. To prevent duplicate keys being created e.g. &pid=12&pid=10, I am researching methods of rewriting the URL:
a)
mysite.com/mypage.aspx/red/green/blue
b)
mysite.com/mypage.aspx?controlname=a,red|b,green|c,blue
Pages using this structure would be publishing content that I would like to get indexed and ranked - articles and products (8,000 products to start, with thousands more being added later)
My gut instinct tells me to go with the first method, but would it would be overkill to add all that infrastructure if the second method will accomplish my goal of getting pages indexed AND ranked.
So my question, looking at the pro's and con's, Google Ranking, time to implement etc. which method should I use?
Thanks!
From an SEO perspective you want to try and avoid the querystring, so getting it into the URL and a short form URL is going to get you a better "bang for the buck" on the implementation side of things.
Therefore, I'd recommend the first.
Why don't use MVC pattern, this way all your link will be SEO ready. Check here, you will find what is MVC and also some implementation in .net!
You can easily make SEO-friendly URLs with the help of Helicon Ape (the software which allows having basic Apache functionality on your IIS server). You'll need mod_rewrite I guess.
If you get interested, I can help you with the rules.
Can you explain in more detail your current architecture and what the parameters all mean? There's nothing really wrong with query strings if it's truly dynamic content. Rewriting ?a=red&b=green&c=blue to /red/green/blue is kinda pointless and it's unclear from the URL what might be on the page.
The key is to simplify as much as possible. Split the site into categories and give each "entity" one URL.
For example, if you are selling products, use one URL per product, with keywords in the URL - e.g. mysite.com/products/red-widget or mysite.com/products/12-red-widget if you need the product ID.