Inline editing with controller v1.2

edited May 2015 in Share
Hello,

I'm having a problem updating the documentation for allowing inline editing for a CMS page where I have some body text but also have a controller and view file.

According to this page: http://www.getfuelcms.com/blog/2010/12/09/learning-fuel-cms-part-1
The controller should have:
$page_init = array('location' = 'contact'); $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init); $fuel_page->add_variables($vars); $fuel_page->render();
But that doesn't work with 1.2.

I've been trying to use:
$vars['layout'] = 'my_layout'; $this->fuel->pages->render('contact/contact',$vars);
Which doesn't give any errors, but I can't access the page variables I need to access so that my view file can work with the following:
<?=fuel_var('body')?>
I can make <?=fuel_edit(6,'body','pages')?> work fine, but I was hoping to be able to display the content and allow it to be edited. This should be very easy, I feel I'm really missing something, or I can't find the correct and updated documentation for this with examples.

Please let me know.

Thanks.

Comments

  • edited 1:42AM
    Try the following:
    $this->fuel->pages->render('contact/contact', $vars, array('render_mode' => 'cms'))
    The different render modes are "views" and "cms".
  • edited 1:42AM
    I tried that, but still nothing.
    <?php echo fuel_var('body','no body present'); ?>
    still outputs "no body present" instead of the content from the CMS Contact page.

    CMS has Pages = Contact with text in body box.
    Controller collects data required, and processes form and outputs variables to view file.
    View file is very plain and only displays the form (more logic to come later) and then displays the above code to show the text from the CMS.
  • edited 1:42AM
    It looks like I'm running 1.2.1 of Fuel for reference.
  • edited 1:42AM
    I'm a little confused about the view file part. So a few things to confirm:
    1. The location value in the CMS of the page variables that you saved is "contact/contact"? 2. That page in the CMS uses the "my_layout" and that layout has a variable of "body" where you can input text?
    3. "my_layout" has a <?php echo fuel_var('body','no body present'); ?> OR is there a view that is being used that has that code in it. If a view, has is that view included into the page rendering?
  • edited May 2015
    No, the Contact Pages page location is set to contact so it shows up at http://sitename.com/contact.
    The controller $vars['layout'] variable points to the proper layout file.
    'contact/contact' is the view file I'm using for the controller.

    The layout is using <?php echo fuel_var('body','no body present'); ?> to display the controller content.

    I never thought about the fact that the layout is using that until now.

    Is there another way to display the controller content as well as the CMS content on this page?

    If I'm going about this all wrong, please let me know. I want to do this the normal way as I'm sure this is something you do quite often (use a controller and allow inline editing of content within the CMS).
  • edited 1:42AM
    Most of the time, if there is a page that needs to have some or all of it's variables created in the CMS, I will just create that page in the CMS. In your case if you are using a view, I would recommend turning that view into a layout. Then in the controller, you can add additional variables as needed:
    $vars['my_var'] = 'My variable'; $this->fuel->pages->render('contact/contact', $vars, array('render_mode' => 'cms'));

    As a side note, If you are just wanting the variables saved in the CMS to be past to the view, you could use something like the following to just grab the saved variables then you can pass them to the view just using $this->load->view('contact', $vars);
    $vars = $this->fuel->pagevars->retrieve('contact');
    The inline editing won't work though unless you use the fuel->pages->render() method.
  • edited 1:42AM
    Based on your content, I'm now using $this->fuel->pages->render() and on the view page I've implemented the $vars = $this->fuel->pagevars->retrieve('contact'); before the rest of the $vars are added.

    It works beautifully.

    On the view page I added the following 2 lines and I think it will work for what I need:
    <?=fuel_edit(6,'body','pages');?> <?=fuel_var('body','')?>

    I can now edit the content inline for this page. It brings up the whole CMS pages page, but it works pretty well :)

    Thanks!
  • edited 1:42AM
    I just found out that fuel_edit doesn't work for non-admin's, even if they have the correct permissions. Is there a reason for that? Is there something I can look into to fix that?

    Thanks! :)
  • edited 1:42AM
    What version of FUEL are you running (1.3 was rolled out today BTW)? I believe this issue has been fixed already.
  • edited 1:42AM
    I upgraded to 1.3 today and noticed 2 things immediately:
    #1) non-super admin were still not seeing the pencil where the var_edit content is for the super-admin
    #2) I get an error on the some pages of the following:
    Fatal error: require_once(): Failed opening required '/home/harkus/dev/vivace/fuel/application/../modules/fuel/libraries/MY_Parser.php' (include_path='.:/usr/local/lib/php') in /home/harkus/dev/vivace/fuel/application/libraries/MY_Parser.php on line 3

    I noticed that My_Parser.php is not in the 1.3 fuel/modules/fuel/libraries folder now. When I tried copying my old one over it gave this error:
    Fatal error: Cannot redeclare class MY_Security_Policy in /home/harkus/dev/vivace/fuel/modules/fuel/libraries/MY_Parser.php on line 383

    Thoughts?
    When I upgraded I only replaced the fuel/modules/fuel folder
  • edited 1:42AM
    How did you upgrade FUEL? The MY_Parser.php file can and should be removed. Regarding the other user, I'm assuming they have full page permissions?
  • edited 1:42AM
    As I mentioned, I replaced (not overwriting) the /fuel/modules/fuel folder.

    As for the user, he's not super-admin, but he does have full Pages: Create, edit, delete, publish permissions.
  • edited 1:42AM
    Ahh, I see there are new instructions due to changes in the application path.:

    Upgrade Instructions
    The vast majority of 1.3 changes to the codebase happened in the fuel/modules/fuel folder. However, there were a few changes that happened in the fuel/application/ folder as well. Our recommended method for upgrading is to use GIT and add the FUEL GitHub repo as a remote. Create a branch from your existing repo, merge FUEL’s master branch into that, resolve any conflicts (there will most likely be some in your fuel/application/config files) and then test before merging back into your own master branch.

    I'll have to figure out how to do all this... it's been on my to-do list to learn this stuff :)
  • edited 1:42AM
    Okay, got the 1.3 update installed and working. However, the non-super-admin is unable to view the pencil for the Pages page content.

    The pencil shows up for fuel_edit for a separate model I created though.

    Very strange.
  • edited 1:42AM
    I just saw an issue that was the opposite almost where if you weren't given the edit permissions for a page specifically you could still edit inline. I've posted a fix for that. Perhaps that fix will help your situation. The change was to the fuel/modules/fuel/config/fuel_modules.php file to the pagevariables config:
    ... 'permission' => array( 'create' => 'pages/create', 'edit' => 'pages/edit', 'publish' => 'pages/publish', 'delete' => 'pages/delete' ),
  • edited 1:42AM
    I applied that to the pages config and it worked perfectly :)

    It was originally:
    'permission' => array( 'pages', 'create', 'edit', 'pages/upload' => 'pages/create', 'publish', 'delete'
  • edited 1:42AM
    Great... that fix has been pushed to the master branch as well.
Sign In or Register to comment.