CodeIgniter Forums
Controller names with more than 1 word - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Controller names with more than 1 word (/showthread.php?tid=11727)



Controller names with more than 1 word - El Forum - 09-21-2008

[eluser]GregX999[/eluser]
How do I name controllers (both the file and the class) that have multiple words? And how do I call them in a URL?

For example, I have this controller: admin_session.php
With a class: AdminSession
And trying to call "www.abc.com/admin_session"

But that doesn't work.

Greg


Controller names with more than 1 word - El Forum - 09-21-2008

[eluser]Mirage[/eluser]
Your controller filename and classname must match. Name your controller class 'Admin_Session'. Or name your file AdminSession.php and adjust your url accordingly. If you want the uri and file/class to be different you could use the router to map them.

HTH,
-m


Controller names with more than 1 word - El Forum - 01-24-2011

[eluser]pesho_h_k[/eluser]
But what if you want to have controllers with a dash ... for better indexing?

For example - site.com/local-business.


Controller names with more than 1 word - El Forum - 01-24-2011

[eluser]BrianJM[/eluser]
[quote author="pesho_h_k" date="1295930942"]But what if you want to have controllers with a dash ... for better indexing?

For example - site.com/local-business.[/quote]

Try using routes.


Controller names with more than 1 word - El Forum - 01-25-2011

[eluser]pesho_h_k[/eluser]
Yes, I did it with routing, just before I wrote to you here ... but I thought that there could be a direct way.

For example, in Zend Framework - if you have a controller/action named with capital letters and not dashes - in the url you'll have only with small letters and dashes. For example:

site.com/new-videos/full-list

this means that you have a controller named "NewVideosController", and an action there named "fullListAction". And just thought that there could be something like this in CI Wink


Controller names with more than 1 word - El Forum - 01-25-2011

[eluser]Nick_MyShuitings[/eluser]
Zend framework is just imposing its own routing conventions for you on the backend. This is an example of CodeIgniter not babying you and holding your hand through the process. Its the price to pay for the flexibility of the system. If you want even more automagical routing magic you could always go with Drupal or Wordpress (sarcasm).


Controller names with more than 1 word - El Forum - 03-26-2014

[eluser]PEN Vannak[/eluser]
Hi,
I have the questions similar to this with the new version of CodeIgniter 2.x on the URL routing.

Example I have the code in controller like this:
Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Manage_employers extends CI_Controller {
function __construct(){
  parent::__construct();
}
public function index(){
  //employer home page here
}

public function employer_register(){
  //employer register here
}

public function employer_activation($email,$code){
  //employer validation account here
}

public function employer_login(){
  //employer login here
}
}

And I would like to get the url like this to support with friendly (SEO):
Code:
http://domain.com/manage-employers
Code:
http://domain.com/manage-employers/employer-register
Code:
http://domain.com/manage-employers/employer-activation
Code:
http://domain.com/manage-employers/employer-login

So in routing config, I have to define all of these url above:
Code:
$route['manage-employers'] = 'manage_employers';
$route['manage-employers/employer-register'] = 'manage_employers/employer_register';
$route['manage-employers/employer-activation'] = 'manage_employers/employer_activation';
$route['manage-employers/employer-login'] = 'manage_employers/employer_login';

So my question is that is there any good solution that I can define the routing by just change the string from "_" to "-" to support with SEO?

Thanks,


Controller names with more than 1 word - El Forum - 03-26-2014

[eluser]ivantcholakov[/eluser]
SEO Friendly URLs in CodeIgniter, http://www.einsteinseyes.com/blog/techno-babble/seo-friendly-urls-in-codeigniter-2-0-hmvc/

Edit: This is a solution for CI 2.x. I am not sure right now, as I remember, such a feature would be built-in CI 3.