marcio
marcio

Reputation: 10512

Dealing with PHP code stored in database with CakePHP

I started to use php a few hours ago. To begin studying I decided to bake a small web app focused in administration of code snippets, something pretty simple. All CRUD operations are working like a charm. The problem is:

User will add any sort of code in the application. It works when adding snippets in any programming language except PHP. When I use the Model::find() method the PHP code (from the snippet of code stored in database) is replaced by an empty string "" and I can't display it in the view.

Why is it happening and how can I solve it?

Thanks for reading.

Upvotes: 0

Views: 272

Answers (1)

deceze
deceze

Reputation: 522135

You're probably just not seeing the output in the browser because the browser tries to render the PHP <? ?> tags as HTML. You'll need to escape the code for output into the browser:

<pre><code><?php echo htmlentities($model['Model']['code']); ?></code></pre>

Upvotes: 1

Related Questions