我正在一个销售产品的网站上工作(一类销售,一类产品).每当我销售产品时,我想在History表中保存该操作,并且我决定使用观察者模式来执行此操作.
那就是:我的类Sales是主题而History类是观察者,每当我调用Sales类的save_sale()方法时,我都会通知观察者.(我决定使用这种模式,因为稍后我也会发送电子邮件,通知管理员等)
这是我的主题类(Sales类从此扩展)
class Subject:
_observers = []
def attach(self, observer):
if not observer in self._observers:
self._observers.append(observer)
def detach(self, observer):
try:
self._observers.remove(observer)
except ValueError:
pass
def notify(self,**kargs):
for observer in self._observers:
observer.update(self,**kargs)
Run Code Online (Sandbox Code Playgroud)
在视图上我做这样的事情
sale = Sale()
sale.user = request.user
sale.product = product
h = History() #here I create the observer
sale.attach(h) #here I add the observer to the subject class
sale.save_sale() #inside this class I will call the notify() method
Run Code Online (Sandbox Code Playgroud)
这是History的更新方法
def update(self,subject,**kargs):
self.action = "sale"
self.username = subject.user.username
self.total …Run Code Online (Sandbox Code Playgroud) 美好的贝壳爱好者!
基本上我有两个文件:
frequency.txt :(多行,包含单词和频率的空格分隔文件)
de 1711
a 936
et 762
la 530
les 482
pour 439
le 425
...
Run Code Online (Sandbox Code Playgroud)
我有一个包含"禁止"字样的文件:
stopwords.txt :(一行,空格分隔文件)
au aux avec le ces dans ...
Run Code Online (Sandbox Code Playgroud)
所以我想从frequency.txt中删除包含在stopwords.txt上找到的单词的所有行
我怎么能这样做?我在想它可以用awk完成......就像
awk 'match($0,SOMETHING_MAGICAL_HERE) == 0 {print $0}' frequency.txt > new.txt
Run Code Online (Sandbox Code Playgroud)
但我不确定......任何想法?提前thxs
我想知道是否有办法从linux命令行调用wordpress(不使用wget).
我的意思是,我想要的是做这样的事情:
命令行:(调用一些php文件并传递相对url作为参数)
$ php /var/www/something.php /my_blog/last_post
Run Code Online (Sandbox Code Playgroud)
响应 :
<div class='post'>
<!-- the last post content -->
<div>
Run Code Online (Sandbox Code Playgroud)
我一直在谷歌搜索和查看Wordpress文档,但我找不到任何东西.
谢谢你的时间!
注意:如果您熟悉Cakephp,我想要做的就是Shell和Tasks,但是对于wordpress
解:
我在WP文件夹的根目录中创建了一个名为command.php的文件:
<?php
include('wp-blog-header.php');
// call the WP functions and stuff, according to the parameters
?>
Run Code Online (Sandbox Code Playgroud)
称之为:
$ php command.php my_args
Run Code Online (Sandbox Code Playgroud) 我正在尝试为cakephp中的save()函数打包一些数据.我是PHP的新手,所以我对如何在代码中实际编写以下内容感到困惑:
Array
(
[ModelName] => Array
(
[fieldname1] => 'value'
[fieldname2] => 'value'
)
)
Run Code Online (Sandbox Code Playgroud)
谢谢!
我是网络开发的新手,为大学项目创建了一种社交网站.每次在用户数据库中有新的消息时,我想在消息菜单中包含更新消息计数(如主页上的facebook消息菜单)
但是学习ajax很令人沮丧,但是在网上搜索并从一些书籍中读取一些主题后,我找到了解决方案,我可以在主页的js文件中进行$ ajax调用,并发送('name'=>'user')存储在我创建的javascript cookie中的数据用户登录后加载主页到php文件,该文件将搜索数据库中的recent_msg表以获取登录用户的最新消息,如果获取php文件后将创建带有代码片段的html文件,另外还有另一个jquery代码会将该文件的片段附加到消息列表菜单中.
PHP部分不是问题,但如何使用jquery ajax api将用户名发送到php文件,这里是我认为我可以应用的代码,但我怀疑如果这是正确的方法
$(document).ready(function{
setInterval ( function()
{
var usr = getCookie("name");
$.ajax ( {
url: '/phpScripts/recent_msg.php',
type: 'POST',
data: usr,
success: function(data){
}
} );
},10);
});
Run Code Online (Sandbox Code Playgroud)
代码中成功函数的目的是什么?