473,895 Members | 2,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CodeIgniter: Default controller

TheServant
1,168 Recognized Expert Top Contributor
Hi all,
I am trying to do something in CI which I cannot find any documentation for. I have set up my .htaccess so that if a file does not exist, and no controller/function is called it goes to the home page, but what I want is this:
Instead of http://mysite.com/controller/function/variable
I just use http://mysite.com/variable and it simply uses the default controller and index function.

The reason is, I am creating a CMS where pages will be retrieved like:
http://mysite.com/page/display/home
But I would much prefer:
http://mysite.com/home
http://mysite.com/contact
http://mysite.com/about

Anyone done this or know how to?
Sep 21 '09 #1
7 8319
Dormilich
8,658 Recognized Expert Moderator Expert
basicly something like this
Expand|Select|Wrap|Line Numbers
  1. RewriteRule ^([a-z])$ page/display/$1
you might add your personal constraints, though.
Sep 21 '09 #2
TheServant
1,168 Recognized Expert Top Contributor
I have been trying to do something like that, however my mod rewrite skills are a bit behind. I have this:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^(application) - [F,L]
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteRule ^(.*)$ index.php/page/index/$0 [PT, L]
Just checks if the file/directory exists, if not, then it should redirect to mysite.com/index.php/page/index/page_requested but it doesn't and I get a 500 error. Any help?
Sep 21 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
don’t know too much mod_rewrite myself…

a) check the syntax (manual)

b) check if you are allowed to use mod_rewrite. wrap the code in
Expand|Select|Wrap|Line Numbers
  1. <IfModule mod_rewrite.c>
  2. </IfModule>
c) use a RewriteBase

d) (has nothing to do with the error) check for a / in the variable string (i.e. use a different RegEx)
Sep 21 '09 #4
TheServant
1,168 Recognized Expert Top Contributor
Well I don't know how to do this. I have realized that my removal of 'index.php/' with the following in my htaccess is not working:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2. RewriteRule ^(application|system) - [F,L]
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteRule (.*) index.php/$0 [PT,L]
Yes I have already changed my config file so that $config['index_page'] = "";

Anyone solved a similar problem?
Sep 21 '09 #5
TheServant
1,168 Recognized Expert Top Contributor
SOLVED!!! I changed this in my config:
Expand|Select|Wrap|Line Numbers
  1. $config['uri_protocol']    = "AUTO";
~to~
Expand|Select|Wrap|Line Numbers
  1. $config['uri_protocol']    = "ORIG_PATH_INFO";
Don't know what it does, but it works!


------------------------------------------------------
Edit:
I have just changed it back to AUTO as I found it stuffs up the search engine friendly URL's, and found another solution. htaccess was changed to include a "?" like so:
Expand|Select|Wrap|Line Numbers
  1. RewriteRule (.*) index.php?/$0 [PT,L]
Sep 21 '09 #6
Markus
6,050 Recognized Expert Expert
CI has this functionality built in: routing. In your config/routes.php file, try some thing like this:
Expand|Select|Wrap|Line Numbers
  1. $route['(a-z+)/?'] = "page/display/$1";
  2.  
Sep 21 '09 #7
TheServant
1,168 Recognized Expert Top Contributor
Ha! Nice work Markus, I was trying to get that to work before with no luck, but tried a little harder and voila!

I have another small problem though... Now none of my error pages work:
The page you requested, 403_shtml, could not be found. <-- This is my error display message.
I have realised that if I run everything through my other function, these pages won't work. Any ideas?
Sep 21 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1517
by: Fritz Bosch | last post by:
We are in the process of refactoring our GUI-based test application for radio equipment and are rewriting a significant part in Python. The new architecture will substantially be based on the model-view-controller pattern, as follows: User Input | v +-------------+ service request service request +-------------+
2
3343
by: Stan | last post by:
I want to make two pages interact through a controller. 1. Page A has a grid and Add button. 2. When Add button is clicked Page B pops up. 3. User enters information and clicks Save 4. Information is saved in database 5. User goes back to Page A which gets new data from database and displays one more row. So, the event handler for Add button on Page A might look like:
1
1286
by: Andy Fish | last post by:
Hi, I have been thinking about the design of a large ASP.NET app and I've read people have a lot of trouble implementing front controller, especially with postbacks, so I don't feel comfortable going down that route at the moment. The main proplem with the page controller pattern seeems to be related to the fact that inheritance is used to implement different types of behaviour and this will lead to large complex class hierarchies....
4
1937
by: Griff | last post by:
Two questions really, the first one "conceptual" and the other more involved with design: 1 - There are two schools of thought where I work on the role of the "controller" task. The first is that the business object will provide the business rules and that the controller will implement the rules and then pass the result set to the view (i.e. do most of the grunt work).
5
3113
by: uspensky | last post by:
We are trying to setup a system to system failover cluster using two nodes (x346) which each have a single hba running to seperate controllers on the DS400. For full redundnancy, IBM recommends dual path from each node but we dont need that. The current setup has two completly seperate paths. hba on node 1 to controller A on DS400 and hba on node 2 to controller B. If i take a controller offline, failover works fine to jumo to other...
1
1948
by: Gerry Vandermaesen | last post by:
Hi, I was looking into CodeIgniter, and encountered the following problem: In codeigniter, you could create a new controller like this: --- class People extends Controller { function index() { ... }
0
4114
by: surfivor | last post by:
I am doing some preliminary research as we are slated to do a project with wordpress. I looked at the wordpress code and realized why I like MVC so much (Rails) because the code mixed in with the rendering looked like a mess to me. I'm not at all sure exactly what we will be doing on the project as the details haven''t been discussed yet. I found that the Wordpress API doesn't look well documented. I set up wordress and created some blog...
1
2924
by: Robertsonjay | last post by:
In mvc you separate view from controller. How do you do that in C#? Many people define an interface for a controller but isn't controller is specific to a form(gui) which all controller contains is handle events from gui controls(button, treeviews, textboxes etc..) which you don't know until you code the form. So is there a point in having an interface for a controller where that controller is tightly tied to a specific form. Having...
5
2289
TheServant
by: TheServant | last post by:
I have recently (today) started doing something worthwhile on CodeIgniter, which is fantastic BTW. I have a problem and I can't figure out what is going wrong. I will post what I have now, but this has been changed so much in the past hour, it hardly reflects my efforts! Control Call $data->settings = $this->settings->get_settings(); Model Function function get_settings() { $query = $this->db->get('settings');
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9837
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11250
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9653
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8030
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5866
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6072
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4291
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.