1

I'm looking for a PHP framework that would allow me to create HTML, not through a templating system like Smarty or Twig (which I really don't like), but directly from my view classes, through methods like:

$this->elementStart('div', array('id' => 'header',
                                 'class' => 'cls'));
...
$this->elementEnd('div');

StatusNet does that, but it's not really a general-purpose framework. Are there any frameworks that work that way?

julien_c
  • 4,942
  • 5
  • 39
  • 54
  • I think most frameworks don't have templates built in as a core functionality, or can be made work that way without too much hassle. Which one(s) would you like to use? – Pekka Sep 28 '11 at 20:06
  • 1
    PHP itself is a templating system. If you think of it that way, then none of them do ;) (i.e. that do not use templates) – Jonnix Sep 28 '11 at 20:07
  • @Pekka Symfony? Or CodeIgniter? I don't really have a preference, actually. Do you think I could just plug StatusNet's XMLWriter wrapper class into one of these? – julien_c Sep 28 '11 at 20:09
  • 1
    seems like creating html in this way would become cumbersome to change and not very designer friendly. but if you must, why not use PHPs DOMDocument class? it can create entire html documents in an OO manor like you desribed. – dqhendricks Sep 28 '11 at 20:15
  • don't get me wrong, i hate templating as well, but creating entire page via OOP seems pretty painful. – dqhendricks Sep 28 '11 at 20:16
  • Why not just write the html? I don't see what advantage you gain using this method. You're typing about 3x as many characters this way. Isn't one of the great benefits of php being able to move in and out of your HTML? – Jared Sep 28 '11 at 20:19
  • @dqhendricks Well, that's what StatusNet does, and I really, really like it. It looks really clean, and pieces of code can be reused very easily. It does really help control the output in a way that writing HTML files doesn't. Which PHP framework would you suggest I plug this kind of OOP output into? – julien_c Sep 28 '11 at 20:22
  • @Jrod An obvious benefit is that you can create XML, XHTML, or HTML outputs from the same view files (for instance, StatusNet has an XMLOutputter as well as a HTMLOutputter, one of which inherits from the other) – julien_c Sep 28 '11 at 20:25
  • @julien_c if you feel that way about your use of html in PHP, perhaps you are using html/views in the wrong way. trust me, pure html and PHP as a template is far easier than building documents in the way that you are describing. not only that, but far easier to edit at a later time. – dqhendricks Sep 28 '11 at 23:05

3 Answers3

0

You can check out Yii. There isn't a template's system like Smarty or anything, you just have your view files with HTML and whatever PHP variables you pass over from your controllers.

EDIT: Heres an old example view I found, didn't have a link so I just pasted. The stuff referencing "widget" etc is just components of the framework, not template engine stuff.

    <!-- blueprint CSS framework -->
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />
    <!--[if lt IE 8]>
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />
    <![endif]-->

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />

    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>

<body>

<div class="container" id="page">

    <div id="header">
        <div id="logo"><?php echo CHtml::encode(Yii::app()->name); ?></div>
    </div><!-- header -->

    <div id="mainmenu">
        <?php $this->widget('zii.widgets.CMenu',array(
            'items'=>array(
                array('label'=>'Home', 'url'=>array('/site/index')),
                array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
                array('label'=>'Contact', 'url'=>array('/site/contact')),
                array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
                array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
            ),
        )); ?>
    </div><!-- mainmenu -->
    <?php if(isset($this->breadcrumbs)):?>
        <?php $this->widget('zii.widgets.CBreadcrumbs', array(
            'links'=>$this->breadcrumbs,
        )); ?><!-- breadcrumbs -->
    <?php endif?>

    <?php echo $content; ?>

    <div id="footer">
        Copyright &copy; <?php echo date('Y'); ?> by My Company.<br/>
        All Rights Reserved.<br/>
        <?php echo Yii::powered(); ?>
    </div><!-- footer -->

</div><!-- page -->

    </body>
    </html> 

DJSunny
  • 1,970
  • 3
  • 19
  • 27
0

At this point there is very fast DooPHP. And you can write your own templating over php. But i dont see a point.

Ernestas Stankevičius
  • 2,420
  • 2
  • 24
  • 30
0

yes there is Yii framework.. It allows both. If u dont want to apply any template call use renderPartial() instead of render(). Plz refer to http://www.yiiframework.com/doc/guide/1.1/en/basics.view

iThink
  • 1,239
  • 3
  • 13
  • 34