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?

Rafael Corrêa Gomes
13.9k15 gold badges92 silver badges190 bronze badges
asked Jul 14, 2017 at 21:02

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());
 }
answered Jul 14, 2017 at 21:21
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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.