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
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
-
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 betterGustavo Souza– Gustavo Souza2017年07月15日 12:36:47 +00:00Commented 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 ..Gustavo Souza– Gustavo Souza2017年07月15日 13:35:10 +00:00Commented 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!Gustavo Souza– Gustavo Souza2017年07月15日 15:12:04 +00:00Commented Jul 15, 2017 at 15:12
Explore related questions
See similar questions with these tags.
default