Assistance in creating an Advanced Module

edited December 2011 in Modules
I'm creating an advanced module called "store" that will be an online store. What I have so far is a folder called "store" in the fuel/modules directory that contains the following directories:

assets
config
controllers
language
views

I've basically followed the instructions on this page in the manual: http://getfuelcms.com/user_guide/modules/advanced so this means I have 3 files in the config folder called "store_constants", "store_routes" and "store", all of which have basic settings applied that I copied from other modules. To do a hello world type test for this module, I created a store.php controller and in the index function it simply echos out "Store" to the page.

It works, but makes me login to Fuel first to see it. How do I set it so that it doesn't authenticate to Fuel to bring up this module, like it does for the blog module?

Erik

Comments

  • edited 1:07AM
    If the controller inherits from Fuel_base_controller, then it will require login. For your admin store controller, name it store_module.php and your front end controller just store.php.
  • edited 1:07AM
    I figured out why I am being asked for a password. It is because my main store.php controller class is extending the Fuel_base_controller, which automatically checks for a logged in Fuel user:

    <?php require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php'); class Store extends Fuel_base_controller { function __construct() { parent::__construct(); // Initialize page_data array $this->page_data = array(); } function index() { $this->load->view('store', $this->page_data); } }

    So, my question is what class should I use in this case to extend my controller class? I see that Fuel_base_controller extends CI_Controller. Should I use that? Are there any other options?

    Erik
  • edited December 2011
    Cool, thanks for the tip. I didn't initially plan on having an admin view in Fuel for the store, but that gets me thinking that it might be a good idea.

    I have an additional question regarding routes. I want to have routes like this:

    example.com/store/checkout/annual
    example.com/store/checkout/3day
    example.com/store/checkout/24hour

    These are routes that will allow people to purchase annual, 3day and 24hour gift certificates for the bike share system. I have a store.php and a checkout.php controller. I have this route defined in a file under the store config folder called store_routes.php:

    <?php $route['store/checkout/(annual|3day|24hour)'] = "store/checkout/index/$1";

    This is currently not working, its returning a 404. Any idea what might be wrong?

    Thanks,
    Erik
  • edited December 2011
    I was able to get this working by adding this line into my application/config/routes.php file:

    $route['store/checkout/(annual|3day|24hour)'] = 'store/checkout';

    It gives me a 404 if I do this:

    $route['store/checkout/(annual|3day|24hour)'] = 'store/checkout/$1';

    Why is the addition of the $1 causing this to break? The goal is to use the 3rd URI segment to apply a different price for each gift certificate type, so I would need that value to get passed to the store/checkout controller. I suppose the other option is to use $this->uri->segment(3) to pull it into the controller, but I still want to find out why it breaks when I add the $1 to the end.

    Thanks
  • edited 1:07AM
    I think it is because you can't pass URI segments to the index method unless you use a controller's _remap method
  • edited 1:07AM
    Awesome, thank you! I just renamed my index function to _remap and it worked. Have to say, most helpful forum on the net for one of the best CMSs on the net, thanks!
  • edited 1:07AM
    Thanks. Glad to help. You are in PDX right?
  • edited 1:07AM
    Yep, I'm just steps away from you over on Grand and Morrison (in front of River City Bicycles). You guys I think are right in front of Clarklewis, I actually had lunch there the other day. We'll have to meet sometime, definitely see your product as a critical part of our business, its made my life a heck of a lot easier!

    Cheers,
    Erik
  • edited 1:07AM
    Ok, I have another question. I have a checkout controller that process a store transaction. Inside of that controller I have the _remap() function and a success() function. The success function gets called when a successful purchase goes through, and it simply loads a view called success.

    I have an issue when I go to example.com/store/checkout/success in that it is loading the checkout view instead of the success view. The checkout view is loaded by the _remap() function in the checkout controller. If I change _remap back to index, it fixes this problem, but then I won't be able to take advantage of having the 3rd URI segment pass in as a parameter to the checkout controller.

    What exactly is the reason for the _remap function? Sounds like I just need to understand the behavior of this function better so that my module can function properly.

    Erik
  • edited 1:07AM
    If you use _remap, it will use that method instead of "success" method in your controller. To grab parameters, you can always use $this->uri->segment(3)... etc. I found this post a while back trying to deal with a similar situation that I thought was an interesting fix to the issue but I haven't actually tried it out (about half way down by Colin Williams):

    http://codeigniter.com/forums/viewthread/135187/

    You are really close. I'll email you directly about meeting up.
Sign In or Register to comment.