Professional CodeIgniter, Thomas Myer
Chapter 8: Last-Minute Upgrades
248
Choosing and Integrating a WYSIWYG Editor
There are dozens of great WYSIWYG editors out there. Many of them are free or low - cost, and almost all
of them give the user a reasonable amount of control over HTML layouts, fonts, headers, and
miscellaneous markup.
There was a time when a lot of folks on the Web knew HTML markup, but that hasn ' t been true for a
long time. More and more people are coming to the Web from a diversity of backgrounds, and nobody
has an interest (it seems) in learning the basics of good markup. This is why you want to provide them
with an easy - to - use tool.
The tool you ' re going to integrate in this example is TinyMCE, available at
http://tinymce
.moxiecode.com
. If you have another favorite tool, feel free to use it.
Once you download the TinyMCE code, pull out the tiny_mce folder (and its contents) and FTP it up to
the already established /js/ folder. Once all those files have been placed on the server, open the admin_
pages_create and admin_pages_edit views, and make a small change before the
< 
h1 
> 
   line:
< 
?php echo $this- 
> 
tinyMce;? 
>
< 
h1 
> 
< 
?php echo $title;? 
> 
< 
/h1 
> 
This is just a placeholder for now! To set the value for
$this- 
> 
tinyMce
, open your Pages controller, and
add the following code to the constructor:
function Pages(){
  parent::Controller();
  if ($this- 
> 
session- 
> 
userdata(`userid')  
< 
 1){
    redirect(`welcome/verify','refresh');
  }
$this- 
> 
tinyMce = ` 
    < 
!-- TinyMCE -- 
> 
    < 
script type="text/javascript" src="'.
base_url().'js/tiny_mce/tiny_mce.js" 
> 
< 
/script 
> 
    < 
script type="text/javascript" 
> 
      tinyMCE.init({
// General option
        s 
mode : "textareas",
theme : "simple"
}); 
    < 
/script 
> 
    < 
!-- /TinyMCE -- 
>
'; 
} 
This loads TinyMCE with the " simple " theme. If you were to load the admin_pages_create view in your
browser, you would see something very similar to Figure 8 - 4 .
c08.indd   248
c08.indd   248
6/10/08   5:37:29 PM
6/10/08   5:37:29 PM