小编boo*_*dev的帖子

Yii - CGridView - 添加自己的属性

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        'title',          // display the 'title' attribute
        'category.name',  // display the 'name' attribute of the 'category' relation
        'content:html',   // display the 'content' attribute as purified HTML
        array(            // display 'create_time' using an expression
            'name'=>'create_time',
            'value'=>'date("M j, Y", $data->create_time)',
        ),
        array(            // display 'author.username' using an expression
            'name'=>'authorName',
            'value'=>'$data->author->username',
//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              'htmlOptions'=>array('class'=>'$data->author->username', 'secondAttribute' => $data->author->id),
//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        ),
        array(            // display a column with "view", "update" and "delete" buttons
            'class'=>'CButtonColumn',
        ),
    ),
));
Run Code Online (Sandbox Code Playgroud)

在选项中value我可以从PHP添加变量,但是对于选项,htmlOptions这是不可能的.为什么?
如何使用PHP变量创建属性?

php yii

5
推荐指数
2
解决办法
8500
查看次数

有没有办法用 PIL 来弥补丢失的字形?

使用 PIL(ImageFont、ImageDraw 等)渲染文本时,如果字体缺少特定字符的字形,它只会跳过该字符。我在文档中没有看到任何用于指定后备字体的机制。是否有一个经过验证的方法可以在 PIL 中使用后备字体来弥补缺失的字形?

python fonts python-imaging-library

5
推荐指数
1
解决办法
1341
查看次数

无法将实体导入数据存储模拟器

我正在尝试将数据存储实体的备份恢复到在本地主机上运行的模拟器中。

我正在使用此位置的指南https://cloud.google.com/datastore/docs/tools/emulator-export-import 这是我迄今为止所做的。

#start the emulator
gcloud beta emulators datastore start --store-on-disk --data-dir "./datastore-emulator" --project=my-project
Run Code Online (Sandbox Code Playgroud)
# set the environment
$(gcloud beta emulators datastore env-init)

# initiate the restore operation
curl -X POST localhost:8081/v1/projects/my-project:import \
-H 'Content-Type: application/json' \
-d '{"input_url":"/home/bogdan/workspace/myCopy/2019-08-19-23-00/2019-08-19-23-00.overall_export_metadata"}'
Run Code Online (Sandbox Code Playgroud)

此时我可以看到模拟器检测到连接,这是日志片段

[datastore] Dev App Server is now running.
[datastore] 
[datastore] The previous line was printed for backwards compatibility only.
[datastore] If your tests rely on it to confirm emulator startup,
[datastore] please migrate to the emulator health check endpoint …
Run Code Online (Sandbox Code Playgroud)

emulation google-cloud-datastore google-cloud-platform

5
推荐指数
0
解决办法
804
查看次数

Flask MongoDB错误:"在应用程序上下文之外工作"

我一直在尝试测试使用PyMongo的Flask应用程序.应用程序工作正常,但是当我执行单元测试时,我不断收到一条错误消息"工作在应用程序上下文之外".每次运行需要访问Mongo数据库的任何单元测试时,都会抛出此消息.

我一直在关注这个单元测试指南:http: //flask.pocoo.org/docs/testing/

我的应用程序的设计很简单,类似于标准的Flask教程.

有没有人有同样的问题?

class BonjourlaVilleTestCase(unittest.TestCase):
    container = {}
    def register(self, nickname, password, email, agerange):
        """Helper function to register a user"""
        return self.app.post('/doregister', data={
            'nickname' :    nickname,
            'agerange' :    agerange,
            'password':     password,
            'email':        email
        }, follow_redirects=True)


    def setUp(self):        
        app.config.from_envvar('app_settings_unittests', silent=True)

        for x in app.config.iterkeys():
            print "Conf Key=%s, Value=%s" % (x, app.config[x])


        self.app = app.test_client()

        self.container["mongo"] = PyMongo(app)
        self.container["mailer"] = Mailer(app)
        self.container["mongo"].safe = True

        app.container = self.container

    def tearDown(self):
        self.container["mongo"].db.drop()
        pass    

    def test_register(self):
        nickname = "test_nick"
        password = …
Run Code Online (Sandbox Code Playgroud)

python unit-testing mongodb pymongo flask

4
推荐指数
1
解决办法
3003
查看次数

我如何在android中的两点之间画线

如何在android中的两个特定经度和纬度点之间画一条线?

在我的应用程序中,我想绘制数据库中给出的两点之间的最短距离路径.

android

3
推荐指数
1
解决办法
1万
查看次数

如何使用uniqid生成6个字符长度的ID?

我的网站有一个部分,为每个帖子生成一个唯一的ID,然后将其发送到数据库.问题是生成的ID总长度为16个字符,我需要id为6个字符.

这是用于生成ID的代码:

$order_id  = uniqid(rand(10,1000), false);
Run Code Online (Sandbox Code Playgroud)

有什么方法可以实现这样的改变吗?

php random unique

3
推荐指数
1
解决办法
1万
查看次数

是什么导致$ model->属性在Yii中无法获得正确的值?

我有这些线actionCreate:

if (isset($_POST['DpcioCbn'])) {
  print_r($_POST['DpcioCbn']);
  $model->attributes = $_POST['DpcioCbn'];
  print_r($model->attributes);
  die();
  ...
}
Run Code Online (Sandbox Code Playgroud)

返回此:

Array
(
    [code] => 34324
    [bn_fa] => dfsf
    [bn_en] => sdf
    [cbn_fa] => sdfds
    [cbn_en] => f
    [description] => dsfsdfsdf
    [update_at] => 1391-03-16
    [active] => 1
)
Array
(
    [active] => 1
    [code] => 34324
    [bn_fa] => dfsf
    [bn_en] => sdf
    [cbn_fa] => sdfds
    [cbn_en] => f
    [update_at] => 1391-03-16
    [id] => 
    [description] => 
)
Run Code Online (Sandbox Code Playgroud)

现场会发生什么description?这个任务的任何事情是Yii吗?

php yii

3
推荐指数
1
解决办法
3329
查看次数

Yii中的Twitter Bootstrap

我是Yii以及Twitter Bootstrap的新手,我正在尝试使用bootstrap提供的文件.我已经将下载的文件夹解压缩到Yii中受保护文件夹的扩展目录中,然后按照http://www.cniska.net/yii-bootstrap/setup.html#setup我的main.php中的代码如下所示:

'preload'=>array('log','bootstrap'),
'import'=>array(
...
'application.extensions.bootstrap.widgets.*',
),
'modules'=>array(
     'generatorPaths'=>array(
        'bootstrap.gii',
      ),

),
'components' => array(
'bootstrap'=>array(
        'class'=>'ext.bootstrap.components.Bootstrap',
),
),
Run Code Online (Sandbox Code Playgroud)

我得到此错误
别名"ext.bootstrap.components.Bootstrap"无效.确保它指向现有的PHP文件.

Q2.除了在Yii的CSS中复制粘贴整个bootstrap css文件之外,还有更好的方法吗?

Q3.我是否必须下载任何额外的内容才能使用bootstrap twitter提供的小部件,例如$ this-> widget('ext.cssmenu.CssMenu',array(...);下载的文件应该放在哪里?

yii twitter-bootstrap yii-extensions

3
推荐指数
1
解决办法
9874
查看次数

使用 HAVING 选择 SQLAlchemy 列的计数和值

我想选择具有相同电子邮件地址且重复次数超过一个的所有联系人的计数。我无法使用 PostgreSQL 在 SQLAlchey 中使用此查询。

SELECT count(*), email FROM contact group by email having count(*) > 1
Run Code Online (Sandbox Code Playgroud)

我试过这个:

all_records = db.session.query(Contact).options(
    load_only('email')).group_by(Contact.email).having(
    func.count('*') > 1).all()
Run Code Online (Sandbox Code Playgroud)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column "contact.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT contact.id AS contact_id, contact.email AS contact_em...
           ^
[SQL: 'SELECT contact.id AS contact_id, contact.email AS contact_email \nFROM contact GROUP BY contact.email \nHAVING count(%(count_1)s) > %(count_2)s'] [parameters: {'count_1': '*', 'count_2': 1}]
Run Code Online (Sandbox Code Playgroud)

我试过这个:

all_records = db.session.query(func.count(Contact.id)).options(
    load_only('email')).group_by(Contact.email).having( …
Run Code Online (Sandbox Code Playgroud)

python postgresql sqlalchemy

3
推荐指数
1
解决办法
4184
查看次数

超级用户在Yii的权利扩展中意味着什么?

我正在使用Yii的权限扩展并收到此错误:

There must be at least one superuser!
Run Code Online (Sandbox Code Playgroud)

我不知道这superuser意味着什么,因为我使用的是用户admin和demo的默认身份验证.阅读权限扩展的文档后,我尝试使用以下命令配置权限:

'rights'=>array(
    'superuserName'=>'admin',
    'install'=>true
),
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我搜索了互联网但没有结果.

php yii yii-extensions

2
推荐指数
2
解决办法
4528
查看次数