0

I'd like to display data from the database table on my frontend screen, I'm trying this way:

Teste/Cadastro/Block/Tabela.php

<?php
class Teste_Cadastro_Block extends Mage_Core_Block_Template
{

        public function getContent()
     {
        $cadastroModel = Mage::getModel('cadastro/cadastro');

        $collections = $cadastroModel->getCollection();

            foreach($collections as $collection)
        {
             print_r($collection->getdata(''));
        }
?>

default/template/cadastro/cadastro.phtml

...
            <div>
                    <?php echo $this->getContent(); ?>
            </div>
...

And in my config.xml I have the declared block.

Does this have to be done through a block or even an action?

1 Answer 1

0

Use your model like that sample:

$cadastroModel = Mage::getModel('cadastro/cadastro');

$collections = $cadastroModel->getCollection()
               ->load();

foreach($collections as $collection){
         print_r($collection->getdata());
    }
3
  • It did not work, it only worked when I called directly in my phtml, but it is not the most correct way to do it, I will do all my phtml to analyze better Commented Jul 15, 2017 at 12:36
  • I think it's a mistake at the time of "pulling" or file to phtml, since it directly in phtml has effect, only that when I pull the file by <? Php echo $ this-> getCollection (); ?> It has no effect .. Commented Jul 15, 2017 at 13:35
  • I solved the error, in my xml I was setting as core / template and was not using my block "cadastro/tabela", thank you! Commented Jul 15, 2017 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.