Return db data in view to doophp

308 Views Asked by At

I want to ask to doophp with what way can I return my db data from the model -controller to my view.

Here is mycontroller:

`class CategoryController extends DooController { 
    public function Index(){ 
        Doo::loadModel('Category'); 
        $category = new Category; 
        Doo::db()->find( $category, array('limit'=>1) ); 
        $this->view()->render('Category/Index', $category); 
    } 
} 

And I have a view (category.html) like this for example:

<!DOCTYPE html> 
<html> 
    <head> 
        <title></title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    </head> 
    <body> 
        <div>{{category.categoryname}}</div> 
    </body> 
</html>`
1

There are 1 best solutions below

0
On

The eseast way to do that is:

class CategoryController extends DooController { 
    public function Index(){ 
        Doo::loadModel('Category'); 
        $category = new Category; 
        Doo::db()->find( $category, array('limit'=>1) ); 
        $this->view()->renderc('Category/Index', array("category" => $category)); 
    } 
}

and then category.php

<!DOCTYPE html> 
<html> 
    <head> 
        <title></title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    </head> 
    <body> 
        <div><?php echo $this->data['category']->categoryname; ?></div> 
    </body> 
</html>`