English 中文(简体)
CakePHP: reusing models, controllers, configuration but not views and routes
原标题:

Our website is going to work as follows:

  • There s a central site www.example.org where everybody can register, change information, manage their business card .
  • Also, everybody will have companyname.example.org. Here users can publish a simple site based on information they change in the main site.

This site is being built on CakePHP. I m wondering what a good setup for this is. After doing some googling it appears to be common to create a separate directory for controllers and models for reusing, but in this case I want to really share all the code, except routes and views.

Is it possible to change routes based on a domainname. Would this be considered appropriate for CakePHP at all. Rather than a solution that does the job, I would prefer to find the best practice.

Thanks!

最佳回答

Solved using this tutorial

问题回答

Off the top of my head, the routing engine in CakePHP has no concept of domains so what you could theoretically do is map a route eg /company1/post/1 to company1.example.com/post/1 using Apache rewrite

Prefixing in routes is possible as I ve used it before to produce a multilingual site eg /en/blog, /es/blog etc so it would be just a case of prefixing the company name in the route.

What you are looking for are themes.

CakePHP 1.3 has a neat implementation of that, but 1.2 works almost as good.

In your AppController, you will want to add something along those lines to load a different theme based on the host:

$mapThemes = array( company.example.com  =>  theme-1 ,  store.example.com  =>  theme-shopping );
$this->theme = $mapThemes[env( SERVER_NAME )];

Of course, possibilities are endless. You can load $mapThemes from the database by letting every user define multiple themes, etc. But that s the general idea and what I believe is the Cake way of doing things.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签