Welcome Guest, Not a member yet? Register   Sign In
How to transfer $data['query'] to Dwoo ?
#1

[eluser]sigork[/eluser]
This test example works:

Controller:
Code:
$this->db->select('articleid ... ');
... ...
$data['query'] = $this->db->get();

$articles = array('articleid' => '123');

$this->dwootemplate->assign('articles', $articles);

View:

Code:
{foreach $articles articleid}
Z{$articles.articleid}
{/foreach}

I get:

Quote:Z123

Correct.

But how to get $articles.articleid from $data['query'] ?

I tried this approach (another test), but it doesn't work:

Code:
...
        $data['query'] = $this->db->get();
        
        $i = 0;
        foreach ($data['query']->result_array() as $row)
        {
               $articles[] = array ($i => '123');
               $i = $i++;
        }
        
        $this->dwootemplate->assign('articles', $articles);

I get:

Quote:Message: Undefined index: articleid

Thanks.
#2

[eluser]Phil Sturgeon[/eluser]
That implementation is being replaced by mine in v1.2 of Dwoo. Get in there early.
#3

[eluser]sigork[/eluser]
[quote author="Phil Sturgeon" date="1259614714"]That implementation is being replaced by mine in v1.2 of Dwoo. Get in there early.[/quote]

I performed the instructions specified here:
http://philsturgeon.co.uk/code/codeigniter-dwoo

(and I added parser to autoload.php). 'dwoo_test' worked correctly.

In a test controller I replaced

Code:
$this->load->view(THEMEDIR.'site/pages_view', $data);

with

Code:
$this->parser->parse(THEMEDIR.'site/pages_view', $data);

If I replace (in View)

Code:
<?php echo $title; ?>

with

Code:
{$title}

it works.

But a question: Should I re-write the controller to use arrays in it, not objects?
Because as I see the objects work (for example, 'title').

Will

Code:
$data['query'] = $this->db->get();

work also, or I should re-write it as an array to use it in View with Dwoo?

Thanks!
#4

[eluser]Phil Sturgeon[/eluser]
Arrays and objects are both Fine. personally I hate passing the query object directly to output as it just seems messy but it does work fine. Read the syntax documentation on the Dwoo wiki for more information.
#5

[eluser]sigork[/eluser]
I took ready examples but sorry, I cannot connect them:

Controller from http://ellislab.com/codeigniter/user-gui...arser.html

Code:
function index()
    {
$data = array(
              'blog_title'   => 'My Blog Title',
              'blog_heading' => 'My Blog Heading',
              'blog_entries' => array(
                                      array('title' => 'Title 1', 'body' => 'Body 1'),
                                      array('title' => 'Title 2', 'body' => 'Body 2'),
                                      array('title' => 'Title 3', 'body' => 'Body 3'),
                                      array('title' => 'Title 4', 'body' => 'Body 4'),
                                      array('title' => 'Title 5', 'body' => 'Body 5')
                                      )
            );

        $this->parser->parse(THEMEDIR.'test_view', $data);
    }

View from http://wiki.dwoo.org/index.php/Syntax#Blocks

Code:
<head>
<title>{$blog_title}</title>
</head>
<body>

<h3>{$blog_heading}</h3>

{foreach $blog_entries title body}
<h5>{$title}</h5>
<p>{$body}</p>
{/foreach}
And I get:
Quote:My Blog Heading

0

Array

1

Array

2

Array

3

Array

4

Array

Smth is wrong, I don't know what Sad

EDIT

I think I found the solution:

Code:
{loop $blog_entries title body}
<h5>{$title}</h5>
<p>{$body}</p>
{/loop




Theme © iAndrew 2016 - Forum software by © MyBB