Reputation: 9412
I am trying to use Php Markdown with Codeigniter.
I saved the file "Markdown.php" as markdown_helper.php.
I have put it in the applications/helpers directory.
I have used this statement to load the helper in my controller.
$this->load->helper('markdown');
I have used this statement to call the defaultTransform function()
$note_body=defaultTransform($note_body);
I am getting this error.
Fatal error: Call to undefined function defaultTransform()
Am I doing something wrong while loading the helper?
Upvotes: 1
Views: 1125
Reputation: 9821
I ended up doing this by creating a thin library which extends the Markdown class.
From: http://blog.gauntface.co.uk/2014/03/17/codeigniter-markdown-libraries-hell/
Put the markdown files from Michel Fortin into the third_party directory, in my case I created a directory called Md and moved the php files into the root of that directory, then create a file called md.php in the libraries directory. Finally in your md.php put the following:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
set_include_path(APPPATH . 'third_party/' . PATH_SEPARATOR . get_include_path());
require_once APPPATH . 'third_party/Md/MarkdownInterface.php';
require_once APPPATH . 'third_party/Md/Markdown.php';
class Md extends Michelf\Markdown {
function __construct($params = array()) {
parent::__construct();
}
}
Then to import and use it:
$this->load->library('md');
$html = $this->md->defaultTransform($markdown);
Upvotes: 1
Reputation: 374
Use $this->load->helper('markdown')
instead of $this->load->helper('markdown_helper')
.
CI automatically appends the _helper.php
part of the filename.
Upvotes: 0
Reputation: 5151
I'm not familiar with Codeigniter, but it looks like PHP Markdown doesn't fit into its definition of a 'helper' being a collection of 'simple, procedural functions' - Markdown.php is object-oriented. See the docs here.
What happens if you keep Codeigniter and PHP Markdown separate? Try including markdown_helper.php
manually using
require_once(APPPATH . 'applications/helpers/markdown_helper.php');
use \Michelf\Markdown;
and then use it like this:
$note_body = Markdown::defaultTransform($note_body);
Upvotes: 1
Reputation: 94
If you using Linux, please try run to find files contain defaultTransform function, and in your code file include that:
fgrep defaultTransform -r -n *
Upvotes: 0