mruz / base-app

The base application in PhalconPHP
63 stars 19 forks source link

Log exception #19

Closed fireburnheart2005 closed 10 years ago

fireburnheart2005 commented 10 years ago

I don't known what it mean $config->app->env == "development" in function app/boostrap.php

public static function log($messages)
    {
        $config = \Phalcon\DI::getDefault()->getShared('config');

        if ($config->app->env == "development") {
            foreach ($messages as $key => $message) {
                echo Debug::dump($message, $key);
            }
            exit();
        } else {

In the public/index.php we use function \Baseapp\Bootstrap::exception($e); and it has $config->app->env == "development"

mruz commented 10 years ago

You can use it for log something (separately of \Baseapp\Bootstrap::exception(\Exception $e);), eg the model validation messages:

namespace Baseapp\Models;

class Users extends \Phalcon\Mvc\Model
{
    public function signup()
    {
        $messages = $validation->validate($_POST);

        if (count($messages)) {
            return $validation->getMessages();
        } else {
            // try to create user
            if ($this->create() === true) {
                return $this;
            } else {
                // log/display errors
                \Baseapp\Bootstrap::log($this->getMessages());
            }
        }
    }
}

On development environment this function displays debug only.

fireburnheart2005 commented 10 years ago

oh,thank you