Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Opt-in Controller, CMS (Pages) & controller class, a little bit confuse

edited July 2017 in Modules
Hi I'm new in fuelcms, just setup version 1.4 and start to play. Very impressive of the performance but I'm a little confuse about the controller.

If I have a controller class defined (let's say 'About'), and the only method is index, so that I can visit http://mysite/about without problem, I created a view file in /fuel/application/views/test/demo.php (without controller class and variable file) and I can browse http://mysite/test/demo, it is opt-in controller, so far so good. But when I created a view file at /fuel/application/views/about/contact.php, it return 404. Is it because I'd a controller class "About", so that all view files in folder '/fuel/application/views/about/' not work (even I didn't have the filename same as any method name in the controller class)

After that I create a page in admin CMS which I set the location to 'about/team (no view file and variable file, just put some content in body variable). And same as before, when I go http://mysite/about/team, it return 404 too (I checked the /fuel/application/config/MY_fuel.php, fuel_mode is set to AUTO)...

So my question is : is it - once the controller class exists (even though the class didn't have a match method name to uri method segment), both admin CMS page and opt-in controller not work ? Or should I need to set something in config file ?

Thanks a lot !

Comments

  • edited 2:20PM
    one more question: when I tried to use fuel_page in controller as below, it always return :
    Unable to load the requested class: Fuel_page, any clue for a newbie ? thanks a lot !


    $vars = array('page_title' => 'Team: My Website');
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', array('location' => 'about/team'));
    $this->fuel_page->add_variables($vars);
    $this->fuel_page->render();
  • edited 2:20PM
    In that "about/contact" example, you'll need to add the method to your controller. If I remember correctly, it use to work in 1.3.2 using some pre_controller hooks to but changes in CI 3 I believe broke that and would require rewriting some core files.
  • edited 2:20PM
    Thanks for your reply.

    In "about/contact" example, I add a method name "contact" in controller class, now it return an empty page (not 404, I think it is because I didn't put any code inside the method). So, is this mean the all opt-in with same controller class name (in this case, opt-in for about/:any) not work if the controller class exists (in this case, About controller) ? (because in my case, if the controller class is not there, the CMS page and view files in folder /fuel/application/views/about/* all work normally.

    And about the fuel_page error : Unable to load the requested class: Fuel_page, please give me some advice how to solve the issue, thank you very much.
  • edited 2:20PM
    Maybe I simplify my questions:
    1. MVC controller and opt-in controller can't be the same (e.g. about/contact is mvc controller, about/team is from cms opt-in, now once I have a about controller class then the opt-in controller always return 404) ?

    2. $this->load->module_library is not work after v1.0 ? (I'm using v1.4)

    Thanks a lot !
  • edited 2:20PM
    1. To your first question, you are correct in that if the controller exists it will route all "about/..." to the "About" controller and you will need to include a method.

    2. For you Fuel_pages error, try the following instead (also found on this page: http://docs.getfuelcms.com/general/opt-in-controllers):
    $vars = array('page_title' => 'Contact : My Website'); $this->fuel->pages->render('about/contact', $vars);

    3. Are you library classes upper case?
  • edited 2:20PM
    Thanks, I figure it now, that is the methods i put in my About class (it is upper case), which "contact" is loading a view file and "team" is loading CMS page (for cms page, I need to specify "rendor_mode" to let it load from cms, although fuel_mode is set to AUTO). Don't know whether it is the correct way to do that.

    function contact() {
    $this->fuel->pages->render('about/contact');
    }

    function team() {
    $vars = $this->fuel->pagevars->retrieve('about/team');
    $this->fuel->pages->render('about/team', $vars, array('render_mode' => 'cms'));
    }

    When I study the user guide, I found a issue at "News Variables File" paragraph (in http://docs.getfuelcms.com/general/pages-variables). It mention about put a variable in .../views/_variables/news.php and then it'll carry to all the pages under the news section. I tried other variables, it really can carry forward work like that, but for 'view' it can't (return 404 when I access http://mysite/news/something, which something is slug and it exists in the database). After I change the variable to $pages['news/:any'] then it work. A little bit strange... anyway I'm enjoy to adapt the framework and thanks for your help.
  • According to this issue, using the About.php Controller and a /views/about.php opt-in controller doesn't work anymore as described here: http://docs.getfuelcms.com/general/pages-variables#static, right?

Sign In or Register to comment.