Welcome Guest, Not a member yet? Register   Sign In
questions from a MODx developer
#1

[eluser]Unknown[/eluser]
I've been developing the last few years in MODx - basically using it as a templating framework while doing all the heavy lifting in snippets. I've gotten used to a certain approach in the application that more or less works for me. For various reasons, I'm looking at other options besides MODx and the I've also used CI to develop several small applications.

I'm wondering if someone could take the time to explain how I would do similar things in CI.


I've gotten use to writing templates that looks like more or less like this

Code:
..(html code here)...
<div class="foomagic">[!show_foo!]</div>
<p>[!newest_bars!]</p>
... (etc)...

where the show_foo and newest_bar are snippets that do whatever I want - and the are completely independent of each other.

in reality - what I do is have a generic snippet called "include" that I call like this:

[!include?file=`snippets/show_foo.php`!]

which loads a file from the filesystem - this way I can use SVN and ftp the files around, work in a dev/test/live environment, etc.

Within include, I have a simple view function
Code:
function view($file, $data=array(), $return=false)
{
  if ($return) {
    ob_start();
  }

  extract($data);
  if (defined('VIEW_PATH')) {
    include(VIEW_PATH.$file);
  } else {
    include($file);
  }

  if ($return) {
    $out = ob_get_clean();
    return $out;
  }
}


and then I have various classes which have the business logic. I generally have a very basic "controller" (just the show_foo.php) which will initiate a Foo object and pass it to a show_foo.tpl.php template as $foo.

Inside the show_foo.tpl.php template I might do:

Code:
<p>NAME: &lt;?$foo->name?&gt;</p>
<p>TYPE: &lt;?$foo->type?&gt;</p>
<p>PRICE: &lt;?view('foo_price.tpl.php',array('foo'=>$foo);?&gt;<p>
<p>RELATED FOOS: <br />&lt;?view('show_related_foos.tpl.php',array('related_foos'=>$foo->getRelatedFoos());?&gt;<p>

and inside my show_related_foos.tpl I might call again the foo_price.tpl.php

I've found the overall approach very successful and I just pass around (complex) objects and let the views worry about displaying them how every they are supposed to.

I'm wondering if/how I can apply this approach to CI. There are two basically aspects of they way I've been doing it in modx that I'd like to be able to do in CI.

1) to have an template for a page which I can then "inject" different controllers. For example - I would like to have a "Blog page" and on that blog page is a sidebar for the newest wiki posts - assuming I have controllers for my blog and I have a wiki controller. I didn't understand how when building the view for the request for /blog/today ( eg controller Blog->today() ) I would also call the content available from (/wiki/newest (eg controller Wiki->newest() ) - is this possible?

2) the ability to have nested views - I just never tried it so I don't know - maybe it's easy - just in the examples I've seen they call view for the header part of the view, the body, and the footer part of the view. I find this approach less than idea because I prefer to be able to work with the html in it's entirely instead of breaking it into different pieces.

Thanks for making it to the bottom,
Yehosef
#2

[eluser]wiredesignz[/eluser]
Check out Modular Extensions HMVC, it's designed for this exact purpose.
#3

[eluser]Unknown[/eluser]
Thanks for the fast reply - I'm still digesting it - I appreciate the link.




Theme © iAndrew 2016 - Forum software by © MyBB