Best OOP method for a layout library I had a code for a layout library which looked like :

$this-&gt;layout-&gt;setLayout($layout)-&gt;setTitle($title)-&gt;render()
etc.


Today I started writing a new code, simpler and smaller :

$this-&gt;layout-&gt;data(array(
    'view_name'     =&gt; 'layout_admin',
    'title'         =&gt; 'Administration',
    'js'            =&gt; 'admin/matrix.chat' 
))-&gt;view('admin/index');


The previous setters/add methods were like :

public function setDoctype($doctype) {
    $this-&gt;doctype = $doctype;
    return $this;
}

public function addJs($name) {
    if(!in_array($name, $this-&gt;js)) {
        $this-&gt;js[] = $name;
    }
    return $this;
}


The new data method :

public function data($data = array()) {
    if(isset($data['view_name'])) $this-&gt;ci-&gt;config-&gt;load($data['view_name']);
    else $this-&gt;ci-&gt;config-&gt;load($this-&gt;data['view_name']);

    // Mark as forbid because are stored in arrays and 
    // I can add values to those
    $forbid = array('css', 'js', 'rss');

    foreach($this-&gt;ci-&gt;config-&gt;config['layout'] as $key =&gt; $value) {
        if(isset($data[$key]) &amp;&amp; !in_array($key, $forbid))
            $this-&gt;data[$key] = $data[$key];            
        else
            $this-&gt;data[$key] = $value;

        if(isset($data[$key]) &amp;&amp; in_array($key, $forbid)) {
            if(is_array($data[$key])) {
                if(count($array) != count($array, COUNT_RECURSIVE))
                    foreach($data[$key] as $key2 =&gt; $value2)
                        $this-&gt;data[$key][$key2] = $value2;
                else
                    foreach($data[$key] as $value2)
                        $this-&gt;data[$key][] = $value2;
            } else              
                $this-&gt;data[$key][] = $data[$key];
        }
    }

    return $this;
}


I changed to this because of the many things that I can update for every page. And use ->setThing would be annoying. But I don't find that my code is so OOP.

Note that I'm using CodeIgniter.

What's the best oop code ? If you want more indications, please tell me I'm new and don't know how to  say more ;) .
The core of your question is whether or not you should use setters ($tpl->setSomeParam()) or a simple array to bind template parameters. While using an array my not seem very OO, it's actually a pretty effective way of decoupling your data from your templates. As you've discovered, having to add a new setter to your layout manager every time you add a new parameter to one of your templates means the layout manager is tightly coupled to all of your templates – not good.

This is pretty common practice these days. Twig, Underscore.js, and many others do the same thing.