做自定义调试方法,我认为使用/创建一个库,但私有函数(如果同意我的观点:控制器是类,对吧?
<?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
物多物,不用几十if
怎么管理呢?
您必须在每个控制器中执行此操作。您应该为此创建一个帮助程序函数。不要忘记将其加载到composer.json上
"autoload": {
"files": ["app/lib/helpers/debug.php"]
}