0

I am trying to get OpenTBS to work with cakephp 2.x but am having some issues. I found the following thread and have followed it but this is for cakephp 1.x

CakePHP + TinyButStrong

The differences I made are as follows:

TbsHelper

class TbsHelper extends Helper 
{
  function getOpenTbs() {
    App::import('Vendor', 'tbs/tbs_class_php5');
    App::import('Vendor', 'tbs/tbs_plugin_opentbs');

    $tbs  = new clsTinyButStrong; // new instance of TBS
    $tbs->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin   
    return $tbs;
    }

} 

mail_merge function (replacing the export function as a download instead of view)

// FUNCTION EXPORT MAIL MERGE
// -------------------------------------------------------------->
function mail_merge()
{
    // Stop Cake from displaying action's execution time, this can corrupt the exported file
    // Re-ativate in order to see bugs
    //Configure::write('debug',0);

    // LOAD THE TBS HELPER
    // --------------------------------------------------------------->
    $this->helpers[] = 'Tbs';

    // GET THE CONTACTS
    // ------------------------------------------------------------->
    $contacts = $this->Contact->find('all', array('limit' => 20,  'contain' => FALSE));
    //debug($contacts);

    // Get a new instance of TBS with the OpenTBS plug-in
    // ------------------------------------------------------------->
    $otbs = $this->Tbs->getOpenTbs(); 

    // Load the DOCX template
    // ------------------------------------------------------------->
    $otbs->LoadTemplate($this->webroot.'/files/data_files/enquiry_letter_sample.docx');

    // Merge data in the template
    // ------------------------------------------------------------->
    $otbs->MergeBlock('r', $contacts);

    // End the merge and export
    // ------------------------------------------------------------->
    $file_name = 'export.docx';
    $otbs->Show(OPENTBS_FILE, $file_name);

    }

I'm getting this error: Fatal error: Call to a member function getOpenTbs() on a non-object in /home/village/public_html/app/Controller/ContactsController.php on line 408

line 408 is: $otbs = $this->Tbs->getOpenTbs();

Any idea what might be going on?

Thanks

Community
  • 1
  • 1
sluggerdog
  • 843
  • 4
  • 12
  • 35
  • Did you declare TBSHelper on ContactsController? – Guilherme Torres Castro Oct 09 '12 at 01:26
  • No, all I did was this line: $this->helpers[] = 'Tbs'; I thought that would load the helper. I just put this at the top: App::uses('TbsHelper', 'View/Helper'); I still get the same error. Thanks – sluggerdog Oct 09 '12 at 01:32
  • Try to declare like in here http://book.cakephp.org/2.0/en/views/helpers.html – Guilherme Torres Castro Oct 09 '12 at 01:34
  • Thanks, I just tried this instead: public $helpers = array('Tbs'); Still I get the same error. – sluggerdog Oct 09 '12 at 01:37
  • Wait a minute, are you trying to use helper in controller ? They are only available on View. Take a look here : http://cakebaker.42dh.com/2007/08/09/how-to-use-a-helper-in-a-controller/ – Guilherme Torres Castro Oct 09 '12 at 01:40
  • Yes Thanks. I am still getting issues, I wonder if using a helper is not the best way to do this? Any suggestions on how to tackle this differently? Error I get now: Fatal error: Class 'Helper' not found in /home/village/public_html/app/View/Helper/TbsHelper.php on line 3 – sluggerdog Oct 09 '12 at 01:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/17724/discussion-between-guilherme-torres-castro-and-sluggerdog) – Guilherme Torres Castro Oct 09 '12 at 01:55

0 Answers0