Coder Social home page Coder Social logo

Templating system about phreeze HOT 5 OPEN

jasonhinkle avatar jasonhinkle commented on June 19, 2024
Templating system

from phreeze.

Comments (5)

jasonhinkle avatar jasonhinkle commented on June 19, 2024

Well, there's a few ways you could go about that. One - if you are feeling adventurous on your home page is to dig into backbone and do some model binding for those recent posts via ajax. If you are not really concerned with it being fancy like that, you can just do it the old fashioned way, for example:

Inside DefaultController->Home you need to do a database read and then assign the results to the template like so:

$criteria = new PostCriteria();
$criteria->SetOrder('CreatedDate', true);  // <- sort descending by created day

$posts = $this->Phreezer->Query('Post',$criteria)->GetDataPage(1,5)->ToObjectArray(); // <- get only 5 records

$this->Assign('posts',$posts);

Then inside ViewDefaultHome.tpl you would loop through them to display. That code will be slightly different depending on whether you're using Smarty or Savant. Here would be the smarty code:

{foreach from=$posts item=post}
<div>{$post->CreatedDate|escape} by {$post->Author|escape} : {$post->Title|escape}</div>
{/foreach}

Savant is just regular PHP code and would look something like this:

<? foreach ($posts as $post) {
    echo '<div>' ;
    $this->eprint($post->CreatedDate . ' by ' . $post->Author . ' : ' . $post->Title);  // using eprint to prevent css exploits
    echo '</div>';
}?>

from phreeze.

xtrasmal avatar xtrasmal commented on June 19, 2024

I will dive into the adventure. I want to take full advantage of Phreeze, so because its Javascript MVC on top of Savant MVC, I need to stick with models.

from phreeze.

jasonhinkle avatar jasonhinkle commented on June 19, 2024

cool. It's mainly going to be javascript/backbone code in that case. The Phreeze REST API is already set up and ready for you to read the data.

Learning backbone/underscore takes a bit of time and you definitely will want to get familiar with their support documentation. It took me about a week to really get comfortable with it. But once you figure it out it will be very liberating and you'll probably have a greater understanding of what Phreeze really is, and how the generated code is in many cases just a suggestion of how you should build things.

I feel like the Javascript that Phreeze generates is pretty decent but not 100% perfect and I'm waiting for somebody to come along with a deep understanding of backbone to help clean it up!

from phreeze.

xtrasmal avatar xtrasmal commented on June 19, 2024

There are alternatives to Phreeze, like the yii framework. I haven't tested it out fully, but after 12 hours I really got frustrated with it. Phreeze feels cleaner, intuitive, easier to setup and smarter, but, more important Phreeze implements backbone. This is a real big plus. Just imagine doing this afterwards :p It would take me ages.
So I'll start working on the documentation and see how backbone works and such, now that I have the authentication
in place.

from phreeze.

xtrasmal avatar xtrasmal commented on June 19, 2024

For everybody who is reading this:

                   <?php foreach ($this->posts as $post => $val): ?>
                    <?php echo $this->eprint($val->Title); ?><br/>
                    <?php endforeach; ?>  

Would get you the parsed data.

from phreeze.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.