2

I currently have a CMS that writes some pages in a database table. In order to render them with Zend_View I have a method that writes them to the filesystem. I'd like to skip that process and render the templates directly from the database.

For example:

<?php
$template = '<html>
<head>
<title>Test</title>
</head>
<body>
<?php echo $this->test ?>
</body>
</html>';

$view = new Zend_View();
$view->test = 'This is a test';
echo $view->render($template);
?>
2
  • 1
    Isnt this working as expected? Commented Jan 9, 2012 at 16:37
  • No, this does not work by default. Zend_View_Abstract::render must be passed a file name. A Zend_View_Exception with message "script '<html> ...' not found in path..." will be thrown. Commented Jan 9, 2012 at 18:09

1 Answer 1

4

Zend_View extends Zend_View_Abstract and declares a concrete implementation of the _run() method (which is invoked by render()). sic:

protected function _run()
{
    include func_get_arg(0);
}

I guess what you want is basically:

class Zend_View_String extends Zend_View // or maybe // extends Zend_View_Abstract
{
    protected function _run()
    {
        $php = func_get_arg(0);

        eval(' ?>'. $php. '<?php ');
    }
}

But that might be slower than writing it to a file and calling include. You can put your file dumping code inside your own _run method instead. Doing so is left as an exercise for the reader.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.