Nicotine

Open source framework for PHP & MySQL

Downloads Page

SEO URL Tips for Controllers and Actions

Controllers and Actions should begin with a letter, followed optional by other letters, numbers and dashes. Suppose you need an URL like /products-available/shoes-for-kids.html This will point to the controller "ProductsAvailable", action "shoesForKids()".

Another example: Suppose you have an action for product page, name(). You need a slug for product name, and an unique id, which commonly is the primary key of the "products" table. Create an action (a method in the controller) like this:

<?php
// Don't suffix class with "Controller", e.g. ProductController!
// Instead, use suffix for models, e.g. ProductModel", in the /workpsce/site/models/ directory.
class Product extends Controller {
    
// The URL will be /product/name/124/laptop-foo-with-128gb-of-ram.html
    // This is OK because that product name "laptop-foo-with-128gb-of-ram" is in the folder "124".
    
public function name($id$slug '') {
    }
    
    
// The URL will be /product/name/laptop-foo-with-128gb-of-ram/124.html
    // This is NOT OK because that product name is "124" and it is in the folder "laptop-foo-with-128gb-of-ram".
    
public function name($slug$id) {
    }
}