Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
从另一个控制器调用静态方法后,它显示错误消息
$shipprice = CartController::calcshipping(); Error: Using $this when not in object context
您永远不会从其他控制器调用控制器。
您可以将代码放入组件或模型中。通过这种方式,您可以在不同控制器之间共享功能,而无需上述黑客攻击。
然后也不需要在这里做任何静态的东西。它可以只是一个普通的对象调用。
$this->MyComponent->calc();
或者
$this->MyModel->calc();
ETC