Okay, the title isn't really explicit, my bad.
It lame title also explains why I'm probably asking a question that's already been asked - i will gladly accept other (answered) questions as an answer :)
So here's the thing:
I'm currently creating a small community website, and I was wondering how I could handle user-generated content. Everything is ready on the database side (I can store the said content) but I'm struggling on how to display individual pages for each post.
I can display a list of them, sure. But how to have one dedicated page for each content that has been generated?
Right now, I'm using controllers to render my different pages, and I can probably use them to render pages based on one entry in my database.
The thing is, I plan on integrating social elements such as a facebook 'share' or even facebook comments. I doubt I can use controllers for that in an efficient way.
So, how do you think I should proceed?
Two Methods but only one real technique.
1) Use Unique SEO URLs with htaccess (Apache System) (ie, domain.com/example/... or domain.com/test/...). htaccess separates the portions of the query string and passes it to whatever page you'd like (ie, index?id=example ).
2) Use a unique subdomains for the users. Install a wildcard subdomain *.domain.com then you can create any subdomain (example.domain.com or test.domain.com) which will still be directed to the base index page. From there you can gather the subdomain and extract the content from the database.
These are your two basic methods. 1 is the most popular standard.
Related
I’m creating websites in PHP since some years but I never had to manage multi-language scenarios. I plan to create from scratch a website which will be available in French, English, Spanish and German, and I’d like to avoid common mistakes! :-)
I already read different blogs and post, and this is actually how I see the things for now:
Regarding the URLs, I will use static routes which will associate each URL to a specific controller/action. This should allow me to have SEO friendly URL, and should be quite fast (I’ll not use regular expressions but compare the URLs parts to define the route to use).
Note that I won’t have too many pages - probably less than 100 so the route shouldn’t be hard to define.
Regarding the user interface, I’ll have one template per language in order to be able to be able to make adjustments (change the buttons, personnalize the design for a specific country, …).
I plan to use the database to store most of the website content (routes, menus, error messages, static page contents, page titles …).
I will separate the localized content in different tables in order to minimize the size of each table.
I chose this option in order to be able to easily edit the content using the GUI (since I want to allow admins to be able to change the translation if they want, without FTP or phpmyadmin access).
I don’t expect any extra charge on the SQL server since the content which should be almost static (content pages, menus, error messages, route list, etc) will be cached, and the cache will be recreated only in case of content update via the GUI.
My question is the following:
- What do you think about my plan? Do you see important drawback regarding the choices that I did? Did I forget something important?
Thanks in advance!
NOTES:
I don't plan to use a framework as I want to do the things by myself in order to improve my knowledge
I'm already used to use UTF8 everywhere.
I follow the MVC pattern.
I'd like to avoid templating language, and keep only PHP in my views.
I am new at web development, and I have started to work on a small website just recently. Now the problem is, that since it is my first time, I move my pages a lot on the server, because of which I have to keep updating all the other pages that link to it. So, I was thinking of a dynamic way of linking the pages, so that I don't have to update at several places, but only at one.
How it is going to work is that,
there is going to be a separate database kind of thing that will contain all the webpages' updated address, and a unique key to identify them. eg. page12345 = "/about/us.php"
and anywhere where I want to include a link to the page, instead of typing .., I'll have to type something like .., or something like that
This method will also enable me to assign tags/categories to pages, and, or add other properties to them. And, I'll probably also use it for media files as well later.
Now, the thing is, I can think of only two ways to do so, one is using an array in PHP, and other is using MySQL database. The array will probably be too much to handle when the site grows and there are, like thousands of pages, on ther other hand, MySQL database will probably prove to be slower, and at the same time more of a hassle.
So what is it that you suggest? Which will be more efficient. Or is there a better way, I am open to any other ideas that you may have.
The typical way to manage that is to not worry about URLs manually at all and leave up to a router. In the end, URLs are just a technical implementation detail of the HTTP protocol. What you really want to do is identify specific pages/actions uniquely. Have a look at any reverse-routing capable router; here the Symfony implementation:
blog_show:
path: /blog/{slug}
defaults: { _controller: 'BlogController::showAction' }
Read this blog post.
This is admittedly a very high level abstraction, using YAML for specifying routes and Twig for templating with a custom defined function. However, it hopefully demonstrates the goal: don't worry about URLs much at all in your actual links. You need to have one canonical place where URLs are defined (the path in the above example), everywhere else you just refer to your target page by name (blog_show here). If you need to move URLs around, there's exactly one place where you need to do so. The thing in the middle that makes this work is the router.
I am currently trying to figure out a way to create templates for a number of pages that look exactly the same. The only thing that is different is the content part.
I have worked with PHP and include() to separate several parts of my pages, but still need something that allows me to set a default layout and styling of an entire page since I will be creating thousands of pages that are identical.
Please help me with some tips! Highly appreciated.
thousands of pages that are identical.
As stated in the comments, you should definitely go with a CMS (Content Management System)
Main features of a CMS:
Allow for a large number of people to share and contribute to stored data
Control access to data based on user role (i.e., define information users or user groups can view, edit, publish, etc.);
Facilitates storage and retrieval of data;
Control data validity and compliance;
Reduces duplicate inputs;
Simplify report writing;
Improve communication among users.
Define data as almost anything: documents, movies, texts, pictures, phone numbers, articles etc.
Content Management of Pages
Reference: http://en.wikipedia.org/wiki/Content_management_system
With that said, unless you want to spend countless hours studying and learning (which is not a bad thing) but it seems that you simply want to get this sophisticated website working, then a CMS is what you really need.
Take a look at what i believe are the top CMS's out there:
Joomla
Wordpress
Dupral
In a nutshell, you just need to get your Host, http://www.godaddy.com/ (not my personal favorite) but for simplicity; godaddy will install the CMS for you with a click of a button, it will setup everything and get you up and running! After that is complete, you can login via the administrator panel and play around with the settings to see how things work.
I would start with WordPress, heres a nice site to get you going once you have everything setup (assuming you go for Wordpress CMS)
http://www.siteground.com/tutorials/wordpress/wordpress_start.htm
http://codex.wordpress.org/Site_Design_and_Layout
Have fun! Hope this helps.
I am building a PHP application. For my application, user's profiles / pages are setup and displayed intially by visiting domain.com/username or domain.com/accountnumber.
My question is this - how do you do that, while retaining the ability to make informative application pages that have the url of domain.com/pagename? My main example of this is vimeo, which has vimeo.com/about, vimeo.com/developers, etc., while allowing you to set your username to vimeo.com/username. My concern is that I will launch my application and not have the ability to create the link I want to in the future because it is taken as a username.
What would be your advice, or what has been your experience? Is there a common list to reserve that is recommended? I am not sure what to do. Thanks for the help.
There are a number of ways you can achieve what you asking - read up on routes and routing to gain a better understanding.
Many frameworks offer a way in achieving what you are asking - Zend Framework being one.
Alterantivly, if you are building it from scratch you could implement a different structure i.e.
domain.com/u/joebloggs
domain.com/user/joebloggs
domain.com/a/123456
domain.com/account/123456
This effectivly ensures your urls cannot be affected by someone username. You'll need to look into Mod Rewrite if using creating your own routes.
There are many frameworks available already that offer this ability, try Zend Framework.
You'll need to read up on Routes with ZF to implemented what it is you require.
The answer is you don't design your urls like that. I know vimeo does it, but they probably have run in to this headache.
A better solution is to namespace your resources. Look closely at stackoverflow's urls for better examples of good url design.
If you are absolutely stuck with this url design, consider organizing your "content tokens" (the bit of the url that identifies the thing you want) into groups, and giving them an order of priority. E.g.:
if token matches a static page, show static page
else search for and show user page by account name
else search for and show user page by account number
When users sign up, don't allow them to use names that are static pages. (You may want to reserve a set of static page names in advance.)
If you make a new static page later and a user name conflicts, you can forcibly change his user name and send him an "I'm sorry" email. This will hopefully be a rare enough occurrence that you don't need to solve it with code.
One way would be to use curl or similar to request domain.com/requestedname at the registration, returning an error to the user if the URL doesn't return a 404. As for future conflicts, there is simply no way to do that. You either have to make a list at the beginning of all potential future reserved words and disallow those usernames (impractical), cross your fingers and hope a conflict doesn't occur (also impractical), request a username change from the user when a future conflict occurs (unprofessional?) or use a different namespace for usernames and system pages.
I am looking for expert advice on how to best serve multiple sites with one Drupal instance (using Pressflow 6.x). Let's consider the company needing this is called "ABC Group of Companies" and it has 3 sister concerns. So, altogether there will be four sites:
www.abcgroup.com
www.company-a.com
www.company-b.com
www.company-c.com
Here are the things that are most interesting:
The users will be shared among all
the sites
Each site will "mostly" host their own content (say the welcome text on home page, or menu items - different for each site)
Some contents, will be shown in all of the sites (say, a company-wide notice....or an employee directory)
The theme for each site will be different
Now, I am thinking of having DNS entry so each of the domain point to the same Drupal installation and when Drupal gets bootstrapped, I would like to sniff into the $_SERVER array to know which site is being hit. I'd then like to load the theme accordingly, show the contents specific to that site, and also show the contents that are shared with all the sites.
To make this happen, so far I have created a node type called "Site" and have created four contents for each of the sites. Then for each other content type (say, Page) I have put a node reference to the "Site" content type with multiple value so when creating a new content, the administrator can specify in which site that content will be showed. However, after that I am stuck.
I have tried to understand Contexts, Spaces, PURL - but haven't figured them out fully yet and I believe I could use the community power to help me out. What do you think is the best approach to handle this scenario ?
It'd be greatly helpful if anybody can suggest a direction.
Regards,
Emran
The way you are suggesting is certainly a way that you could do it, but have you considered domain access? I have used it in the past and found it to be very useful. there is also quite a large collection of modules which work with it. Different themes, Options as to which nodes should appear on which sites and shared users are all features that it has.
Hope this helps!
http://drupal.org/project/domain
First up, I strongly second hookds suggestion of using Domain Access Module for this (+1). It has extensive support/features for your scenario and already covers most of the hard parts you'd need to solve yourself otherwise.
Second, if you insist on trying to do this yourself, I can assure you that it is possible, as we have done something pretty similar recently (some special requirements ruled out domain access), but it was a lot of work, especially when functionality provided by contributed modules would not fit well into our 'unusual' scenario.
Given the multitude of special cases you'd have to cover, it is hard to point out a general direction (apart from suggesting to use Domain Access Module ;) but one major point would be to check out the custom_url_rewrite_inbound()/custom_url_rewrite_outbound() function combo. These will allow you to do pretty low level URL manipulations for incoming requests, as well as for URLs generated for output, both of which you'll need to do if you you want to serve multiple domains from the same instance.
Did I mention that you should check out Domain Access Module before you try to build this yourself?
It sounds like there will be virtually no content shared between these sites. Will you be wanting a single login across all sites?
Remember, Domain Access uses 1 shared database.
You could also just do a regular multi-site install, and share certain tables.
I give Domain Access two thumbs up, but just make sure you really need what it actually does.
Also, I would look into the Feeds.module. You can pull content from anywhere (especially another drupal site) and it imports it directly and creates nodes and fields automatically from it.