CodeIgniter Forums
vars in config / route.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: vars in config / route.php (/showthread.php?tid=62695)



vars in config / route.php - dem80 - 08-16-2015

Hi I am creating a website in more languages. I have 9 maingroups in 4 languages.

I want to create (if possible) something like this:

$route['(women|men|shoes|kids|bodywear|eyewear)']='maingroups';

But I want to put the string 'women|men|shoes|kids|bodywear|eyewear' as a varibele. But I cannot find if it is possible to do something like so:

$maingroups=array();
foreach ($tree as $node) {
          $maingroups[]=$node->cat_name;
  }

$pages = implode('|' , $maingroups)
$route[$pages] = 'maingroups';

Can someone help? Thanks and kind regards.


RE: vars in config / route.php - kilishan - 08-16-2015

Yes, you can use variables, etc in your routes file to build your routes.

I don't know where you're getting $tree from. When the routes file has been read in, you don't have access to much of the CodeIgniter code so it would all depend on where that variable was coming from. Without that info I can't say if that exact code is possible.

Have you tried it?


RE: vars in config / route.php - CroNiX - 08-17-2015

Try:
Code:
$route['(women|men|shoes|kids|bodywear|eyewear)']='maingroups/index/$1';

Then the index method of the maingroups controller would look like:
Code:
public function index($type = null)
{
  echo $type; //$type will be women, or men, or shoes, etc.
}