Search code examples
phpformsclassconcrete5

Concrete5 - Class method not working


I am trying to create a custom dashboard application in Concrete5 for a client of mine. I am having trouble getting methods inside the controller class for the page to work.

You can view my post on the official concrete5 forums for a completely in-depth explanation here: https://www.concrete5.org/community/forums/customizing_c5/call-to-controller-method-throwing-404-page-not-found-error/

This is my view.php file for the dashboard page which generates the form

<?php  defined('C5_EXECUTE') or die(_("Access Denied."));

$dh = Loader::helper('concrete/dashboard');
$ih = Loader::helper('concrete/interface');

$uNamePosted = "Pants";

$help = 'This add-on works in conjuction with my XML Export add-on ';
$help .= 'this is a new dashboard page which allows you to open these';
$help .= 'XML files, edit and then save them, so that you can then';
$help .= 'import them using Core Commerce Import.';

echo $dh->getDashboardPaneHeaderWrapper(t('XML Viewer'), t($help), 'span8', false);

?>
<div class="ccm-pane-body">
    <?php echo $uNamePosted; ?>
   <form method="post" 
    action="<?php echo $this->action('test_form'); ?>">
    <input type="text" name="uName" value="" /> 
    <input type="submit" value="Search" />
    </form>
</div>
<?php  echo $dh->getDashboardPaneFooterWrapper(false); ?>

This is the contents of my controller.php file for the dashboard page

<?php  defined('C5_EXECUTE') or die(_("Access Denied."));



    class DashboardCoreCommerceXmlViewerController extends Controller {
      public function test_form() {
        $uName = $this->post('uName');
        $this->set('uNamePosted', $uName);
        }
    }

Expected functionality: I type something in the box and push search, the dummy value of 'pants' is changed to what I typed

What is happening: Nothing, when I hit the search button the page reloads and no information is changed.

I am following a tutorial by a C5 staff member located here: http://andrewembler.com/posts/basic-mvc-in-concrete5/

As far as I can tell this should work but nothing happens when I hit search. I have verified that the function inside the class is being accessed because a print("sometext"); at the top of function creates the following error: Cannot modify header information - headers already sent by (output started at public_html/site/packages/xml_viewer/controllers/dashboard/core_commerce/xml_viewer/controller.php:6) in public_html/site/concrete/core/libraries/view.php on line 963

Which is expected because its printing after headers have been sent, but it does prove that concrete5/.PHP is finding the function however nothing happens with the line

$this->set('uNamePosted', $uName);

Any help is appreciated, thanks in advance. Even the tutorial from their own staff member says this should be working.


Solution

  • Answered on Conrete5 forums.

    I had a brain fart and was setting the variable to 'pants' inside view.php not inside controller.php

    Doh!