是否可以向以前声明的对象添加新属性?这里有一些代码要澄清(使用uploadify jquery插件):
$('#featuredimageupload').uploadify({
'uploader' : base_url + 'media/js/uploadify.swf',
'script': base_url + 'post/uploadflash',
'multi' : true,
'queueID' : 'queue',
'cancelImg' : base_url + '/media/images/cancel.png',
'fileDesc' : 'Allowed Types: (*.jpg,*.png,*.gif)',
'fileExt' : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
'queueSizeLimit' : 9,
'sizeLimit': 1000000,
'method' : 'GET',
'buttonText' : 'Browse',
'onComplete' : function(event, queue, obj, response, data){
if(response =='false'){
alert('Maximum number of images reached!');
$('#uploader').uploadifyClearQueue();
return false;
}
},
'onError' : function(event,queue,file,error){
alert('An error occured. No files were uploaded');
$('#uploader').uploadifyClearQueue();
}
});
Run Code Online (Sandbox Code Playgroud)
然后做点什么
$('#form').submit(function(){
$('#featuredimageupload').uploadify({scripData : data})
}) …Run Code Online (Sandbox Code Playgroud) 得到这个代码:
$('#hotels').jqGrid({
url : base_url + 'administrator/ajaxhotel',
datatype : 'json',
mtype : 'GET',
colNames : ['Hotel ID' , 'Hotel Name', 'Hotel Location','Type', 'Status', 'Active', 'Date Added'],
colModel : [
{name: 'id', index: 'id'},
{name: 'name', index : 'name', editable: true, editrules:{required:true, custom:true, custom_func: check_hotel_exists}, formatter: hotel_link_formatter, unformat:hotel_link_unformatter},
{name: 'location', index:'location'},
{name:'type', index:'type'},
{name: 'status', index: 'status', editable:true, edittype:'select', editoptions: {value: 'normal:Normal;sold:Sold'}},
{name: 'active', index: 'is_active', width: 100, resizable: false, editable:true, edittype:'select', editoptions:{value: '1:Active; 0:Not Active'}},
{name: 'date_added', index: 'date_added'},
], …Run Code Online (Sandbox Code Playgroud) 我已经读过PHP的"可能"弱点是它处理"并发"的方式.只有会话和cookie来跟踪用户状态,PHP如何高精度地处理以下情况:
多个用户签出一个项目,库存中只有1个库存(抱歉语法错误,但你已经得到了很多照片)
多个用户使用相同的登录详细信息登录同一用户帐户
多个用户同时编辑同一图像(虽然这在现实生活中很少发生)
或任何其他需要多线程处理的事务
(如果我在这里误用了条款,我道歉)
我把这段代码展示给了我的朋友
$user->attempts++; // the attempts property returns an int
Run Code Online (Sandbox Code Playgroud)
并且他就像是说代码是多么愚蠢,漫无边际的数字运算符会在附加到对象时产生语法错误; 事情是它按照我的预期工作(增加尝试1,哦是的,我测试了它)
所以我问,为什么这到底有效?
语言综合查询.现在我知道缩略词了.我见过C#示例,但无法理解它们.我可以在PHP中使用它们吗?我可以和ORM一起使用吗?有没有PHP MVC框架有这个?
所以这是设置:
如果我在设置文件的INSTALLED_APPS部分删除了应用程序(名称为myapp),整个站点工作正常我在apache2.conf中添加了WSGIPythonHome
我可以通过Django(python manage.py shell)中的交互式python shell成功访问应用程序.我可以创建,更新和删除数据.
我正在使用Ubuntu 10.04 Lucid Lynx的标准Apache 2设置(启用站点,启用mods,apache2.conf等)
我正在运行位于/ home/ygamretuta/dev/myproject的virtualenv
我的django项目位于/ home/ygamretuta/dev/site1
错误日志文件说明(最后2行):
File "/home/ygamretuta/dev/myproject/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
TemplateSyntaxError: Caught ImportError while rendering: No module named myapp
Run Code Online (Sandbox Code Playgroud)
我的django.wsgi包含这个:
import os, sys
sys.path.append('/home/ygamretuta/dev')
os.environ['DJANGO_SETTINGS_MODULE'] = 'site1.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Run Code Online (Sandbox Code Playgroud)
我的site1.com虚拟主机文件(包含在sites-available文件夹中)包含此文件(删除了其他详细信息):
WSGIDaemonProcess ygamretuta processes=2 maximum-requests=500 threads=1
WSGIProcessGroup ygamretuta
WSGIScriptAlias / /home/ygamretuta/dev/site1/apache/django.wsgi
Run Code Online (Sandbox Code Playgroud)
我能错过什么?如果自定义应用程序(我使用manage.py startapp制作的应用程序)未被注释掉,我将收到e 500内部服务器错误
我知道这听起来有点愚蠢,但作为Django(甚至Python)的初学者,我只想知道如何从ADMINS元组访问电子邮件地址,甚至可以访问管理员名称.
我读到元组是语义的,有点像轻量级结构.因此,如果是这种情况,我可能能够访问这些语义并执行"类似字典"的操作,即ADMINS ['email'].知道这一点,我如何检索元组中的管理员电子邮件和名称?
提前致谢!
我正在阅读Sitepoint的Simply Rails一书,并给出了这些模型:
story.rb
class Story < ActiveRecord::Base
validates_presence_of :name, :link
has_many :votes do
def latest
find :all, :order => 'id DESC', :limit => 3
end
end
def to_param
"#{id}-#{name.gsub(/\W/, '-').downcase}"
end
end
Run Code Online (Sandbox Code Playgroud)
vote.rb
class Vote < ActiveRecord::Base
belongs_to :story
end
Run Code Online (Sandbox Code Playgroud)
并给出了这个装置
stories.yml
one:
name: MyString
link: MyString
two:
name: MyString2
link: MyString2
Run Code Online (Sandbox Code Playgroud)
votes.yml
one:
story: one
two:
story: one
Run Code Online (Sandbox Code Playgroud)
这些测试失败:
story_test.rb
def test_should_have_a_votes_association
assert_equal [votes(:one),votes(:two)], stories(:one).votes
end
def test_should_return_highest_vote_id_first
assert_equal votes(:two), stories(:one).votes.latest.first
end
Run Code Online (Sandbox Code Playgroud)
但是,如果我颠倒了故事的顺序,对于第一个断言,并为第一个断言提供第一个投票,它通过
story_test.rb
def test_should_have_a_votes_association
assert_equal [votes(:two),votes(:one)], stories(:one).votes …Run Code Online (Sandbox Code Playgroud) 我即将使用Apache Hadoop,标题为:
Apache Hadoop项目开发了用于可靠,可扩展的分布式计算的开源软件.
我可以将"可伸缩性"与编程联系起来,但我只是不知道这种"分发"如何在我的开发中帮助我.根据维基百科:
分布式系统由通过计算机网络进行通信的多个自治计算机组成.计算机彼此交互以实现共同目标
那么这是否意味着我可以在多台计算机上部署我的网络应用程序并进行某种"强烈计算"?我想到的术语是内容交付网络和云计算.
所以我有这个型号代码:
def self.cleanup
Transaction.where("created_at < ?", 30.days.ago).destroy_all
end
Run Code Online (Sandbox Code Playgroud)
而这个rspec单元测试:
describe 'self.cleanup' do
before(:each) do
@transaction = Transaction.create(seller:item.user, buyer:user, item:item, created_at:6.weeks.ago)
end
it 'destroys all transactions more than 30 days' do
Transaction.cleanup
expect(@transaction).not_to exist_in_database
end
end
Run Code Online (Sandbox Code Playgroud)
与这些工厂:
FactoryGirl.define do
factory :transaction do
association :seller, factory: :user, username: 'IAMSeller'
association :buyer, factory: :user, username: 'IAmBuyer'
association :item
end
factory :old_transaction, parent: :transaction do
created_at 6.weeks.ago
end
end
Run Code Online (Sandbox Code Playgroud)
使用此rspec自定义匹配器:
RSpec::Matchers.define :exist_in_database do
match do |actual|
actual.class.exists?(actual.id)
end
end
Run Code Online (Sandbox Code Playgroud)
当我将规格更改为:
describe 'self.cleanup' do
let(:old_transaction){FactoryGirl.create(:old_transaction)} …Run Code Online (Sandbox Code Playgroud) php ×3
django ×2
jquery ×2
python ×2
javascript ×1
jqgrid ×1
linq ×1
mod-wsgi ×1
object ×1
rake ×1
rspec ×1
ruby ×1
unit-testing ×1
uploadify ×1
virtualenv ×1