0

Doing custom debug method, I thought use/create a library but a private function (if agree with me: controller are classes, right?) is a comfortable piece to access/use.

<?php
class CartController extends BaseController {
  // is well decalared?
  protected $var;

  public function index() {
    // https://github.com/Crinsane/LaravelShoppingcart#example
    Cart::instance('shopping')->add('192ao12', 'Product 1', 1, 9.99);
    Cart::instance('shopping')->add('1239ad0', 'Product 2', 2, 5.95, array('size' => 'large'));
    // want to use $cart
    $cart = Cart::content();
    // comment to continue
    $this->_debug($cart);

    /* code */
  }

  private function _debug($var) {
    $this->var = $var;
    // 'echo' is a little hero, a view? if i can't avoid it i'll do
    echo '<pre>';
    var_dump($this->var);
    echo '</pre>';
    die();
  }
}

$var full of objects and things, how to manage it without using dozens of ifs?

4

1 回答 1

1

您必须在每个控制器中执行此操作。您应该为此创建一个辅助函数。不要忘记将它加载到 composer.json

"autoload": {
    "files": ["app/lib/helpers/debug.php"]
}
于 2013-10-08T18:54:52.200 回答