Welcome Guest, Not a member yet? Register   Sign In
Title in url
#4

(07-05-2017, 05:04 AM)tonny16 Wrote: Thank you for your answer.

I have an idea (good / bad to you to tell me).
I thought: if I create a controller for each category, and that in its controller I put functions, for each software. What do you think ?

So the url will give /[category]/[name_software]

But how in my controller I can only display the article of the id corresponding to my tutorial?

If you have categories in the database and then the products in the database, you can make the entire solution database driven (or you can add categories to the database and categorize your products and then use this solution...)

if you want sitename.com/category/product name, you would need to do that in the default controller for the site using the remap function.

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Welcome extends CI_Controller {
 
 function 
__construct() {
 
parent::__construct(); 
 }
 
 function 
_remap($method){
 
$param_offset 2;

 
// Default to index
 
if ( ! method_exists($this$method)){
 
// We need one more param
 
$param_offset 1;
 
$method 'index';
 
  }

 
// Since all we get is $method, load up everything else in the URI
 
$params array_slice($this->uri->rsegment_array(), $param_offset);

 
// Call the determined method with all params
 
call_user_func_array(array($this$method), $params);
 }

 
       function index($category='',$product='') {
 
// check if the parameters aren't empty
 
if ($category != '' && $product !='') {
 
     // load models for products, filter/clean incoming data, find & display the product page
 
     exit(); // stop executing here
 
}
 
// no category and product, then load the default home page here
 
       

If your category/product names aren't URL friendly, then you'll need to add a column to the database for URL friendly text, populate it and search off of that.
Reply


Messages In This Thread
Title in url - by tonny16 - 07-05-2017, 02:32 AM
RE: Title in url - by InsiteFX - 07-05-2017, 03:48 AM
RE: Title in url - by tonny16 - 07-05-2017, 05:04 AM
RE: Title in url - by Kaosweaver - 07-05-2017, 08:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB