Part of the EllisLab Network
   
2 of 2
2
I’m at a standstill….need help with controllers (theory)
Posted: 06 September 2008 02:07 PM   [ Ignore ]   [ # 16 ]  
Research Assistant
RankRankRank
Total Posts:  499
Joined  05-30-2008

ontguy, I don’t know what Colin does… but that is basically a good way to group it.

In your controller it could be something like

<?php

class Bike extends Controller {

  
function Bike()
  
{
    parent
::Controller();
    
$this->load->helper('url');
  
}

  
function add()
  
{
    $this
->load->view('bike/add');
  
}

That’s a basic example of how I would do it.

Profile
 
 
Posted: 06 September 2008 03:57 PM   [ Ignore ]   [ # 17 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2774
Joined  07-27-2006

I just have a single sub-folder in views like:

app/views/bike/bike_form.php
app/views/bike/part_form.php
app/views/bike/manufacturer_form.php
app/views/bike/bike.php
app/views/bike/part.php
...

And those are just fragments of the final pages that are rendered.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 06 September 2008 04:13 PM   [ Ignore ]   [ # 18 ]  
Lab Assistant
RankRank
Total Posts:  140
Joined  04-24-2007

I gave this structure a try:

app/controllers/bike.php
app/controllers/bike/part.php

When I go to URL/bike/part
it gives me a “404 Page Not Found”

When I removed the file bike.php, it works.

Did any changes need to made to CI through extensions or otherwise for this to work?

 Signature 

CI Bookmarks

Profile
 
 
Posted: 06 September 2008 04:22 PM   [ Ignore ]   [ # 19 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2774
Joined  07-27-2006

Huh.. you’re right, ontguy. Guess we’ll need to use routes for this or rethink the structure. That’s frustrating, but it makes sense. Otherwise, CI would find bike.php and think “okay, lemme instantiate this Bike class,” then when it inevitably doesn’t find the “part” function, it would have to start over and look for a ‘bike/part.php’ file, and continue on. Guess that’s not such a stretch, but it’s obvious to see that this is not what’s happening.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

Profile
 
 
Posted: 06 September 2008 05:02 PM   [ Ignore ]   [ # 20 ]  
Lab Assistant
RankRank
Total Posts:  140
Joined  04-24-2007

I’m glad it does the same for you smile
Good to know I’m going crazy.

A workaround to this maybe to extended Router.php (_validate_request) and have it check for the directory first then the file (I tried it and it doesn’t seem to work; the controller in the directory works but the controller doesn’t).

I found this in my search, the file directory name issue comes up in this thread: http://codeigniter.com/forums/viewthread/46120/

 Signature 

CI Bookmarks

Profile
 
 
   
2 of 2
2