从 CakePhp 中的控制器创建日志
创建日志和日志的最佳方式是什么? CakePHP 的历史。我在想是否有一种方法可以创建一个“访问”一个表的助手,然后我在我想要的每个控制器中调用这个助手。但是,我读到这不是 MVC 标准。怎样才是正确的做法呢?
我很感谢你花时间回答我这个问题。谢谢!
What is the best way to create logs & history in CakePHP. I was thinking if there is a way to create a Helper "that accesses" one table and then I call this helper inside of each controller that I want. However, I have read that this is not MVC standard. How would it be the correct way to do that?
I appreciate your time spent answering me that. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是行为的目的。
我从这里使用 LoggableBehavior:
https://github.com/alkemann/CakePHP-Assets /blob/master/models/behaviors/logable.php
就像一个魅力。然后,如果您愿意,它们将被获取并显示在视图中。
thats what behaviors are for.
I use the LoggableBehavior from here:
https://github.com/alkemann/CakePHP-Assets/blob/master/models/behaviors/logable.php
works like a charm. they are then fetched and displayed in the view, if you want to.
只需为此目的实现不同的日志引擎即可。 CakeLog 类实际上有点像观察者,而日志引擎则像侦听器。
只需使用 CakeLog::write() 和自定义引擎,该引擎可以使用 ClassRegistry::init() 在构造函数中加载日志模型,并将传入数据从 write() 传递到模型。
该手册将帮助您。 http://book.cakephp .org/2.0/en/core-libraries/logging.html#creating-and-configuring-log-streams
Just implement a different log engine for that purpose. The CakeLog class actually works somewhat like an observer and the log engines like listeners.
Simply use CakeLog::write() and your custom engine that could load your log model in the constructor using ClassRegistry::init() and pass the incoming data from write() to the model.
The manual will help you with that. http://book.cakephp.org/2.0/en/core-libraries/logging.html#creating-and-configuring-log-streams