A
A
Alexander Ivanov2016-05-21 18:25:59
Phalcon
Alexander Ivanov, 2016-05-21 18:25:59

Why does phalcon output Undefined variable?

the source
at first did everything, too, everything was deduced from the tutorial database,
then he created his own database, connected it and the warnings
started rolling Notice: Undefined variable: invo in .... 3
Warning: Invalid argument supplied for foreach() .... 3
index.volt

{{ content() }}
{% for contact in invo %}
    <p>{{ contact.name }}</p>
{% endfor %}

models/Invo.php
class Invo extends \Phalcon\Mvc\Model
{
  public function initialize(){
    $this->setSource('contact');
  }
}

InvoController.php
public function indexAction(){
    $invo = Invo::find();//при вар дампе значение не пусто, значит выводиться должно
    $this->view->setVar("contact", $invo);
  }
}

Everything is fine with the config.php, so if it didn't connect, it would display this "Table 'contact' doesn't exist in database when dumping meta-data for Invo"
The database connection string looks like this:
/**
 * Подключение базы данных
 */
$di->set('db', function() use ($config){
  return new DbAdapter($config["database"]->toArray()); //берём подключение из config.php
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2016-05-21
@cimonlebedev

45 minutes of stupidity because of one line:
$this->view->setVar("invo", $invo);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question