Wysiwyg editor for view files?

I have seen several extensions and topics for wysiwyg editors, I have even tried a couple but they all seem to show how to update content in a model.

I need to know if there is an easy way to edit view file content directly.

I have several sites that are small and have no need for a database backend, they are not mine. I only set them up for friends and relatives. I can either continue to update them manually for free or show them how to update them.

The problem is that these are non-technical people and the idea of explaining html, php, and the directory structure of yii is not an option. My thought was to give them a wysiwyg editor that they can be more familiar with (like word) that they can invoke to edit the pages directly without knowing html. The issue I have run into is that I have read the documentation and still cannot figure out how to edit the view files (not data in a database).

I have tried to use TinyMCE, editme, editor, etc…

I even tried a standalone java script named aloha.

I liked aloha because it gives a nice border around editable text when you hover over the elements that are editable. There is no border when you are not hovering over editable content.

Again, these all want a model to save and I have no database. I want to know how to edit the raw view files and I want to be able to do it from the same page. For example if I am on the home page (views/index.php), if I am logged in I want a visual cue when I hover over editable content. Then I should be able to edit and save the changes to that page when done or cancel changes if I don’t like them.

Can anyone show me how to do this?

Is there another extension I am missing?

Is there a post that answers this already?


it’s seems to danger to do this,

but you can still try like this

// in some controller

if(isset($_POST['content'])) {

  $content = $_POST['content'];

  $viewFile = CController::getViewFile('index');

  file_put_contents($viewFile, trim($content));




Yeah that would work but… I was kind of hoping aloha, tinymce, or another editor extension had a more native approach.

This can be made more safe and will take some extra code but I guess this is the approach I will take. I will couple aloha with some rbac checks and limit to ONLY the files I want editors/admins to be able to edit.


If anyone else has some thoughts on a clean way to do it in aloha or another editor, please feel free to chime in.

For any that may be interested, basically I used the Aloha widget (yii-aloha-editor) and coupled it with a model that I added some code similar to what Francis.TM posted above. I only make the widget available when a user is authenticated. So far it is working great!

There are some slight downsides…

  1. To make sure ONLY html content is edited I split each editable view into 2 files.

  2. It requires a post to the controller, the model to sanitize, and then to overwrite the content file.

The first point is less than optimal, but it is at least cleaner than trying to parse sections of a file that contain only editable html as opposed to php that should not be edited.

The second point makes it slightly slower than working with data from a query, but not not noticeably so far.

If any are interested I can post the model, view, and controller code.

It is a neat work around when a database is not an option or not needed. I use it because I have non-technical staff in a small office that need to edit portions of the content on certain pages (news, home, etc…). They do not know HTML or PHP and have no desire to learn. Neither do they want to learn how to use an IDE or editor and upload code after. A database would be overkill to change the news page once a month or so.