1

我在我的控制器中使用这个 Yii 代码来搜索 POST

$model = Questions::model()->with( 
  array( 
    'categories' => array (
      'select' => 'name',
      'condition' => 'categories.id=:cat_id',
      'params' => array (':cat_id' => $_POST["Questions"]["categories"])
    ),
    'countries' => array (
      'select' => 'name',
      'condition' => 'countries.id=:cou_id',
      'params' => array (':cou_id' => $_POST["Questions"]["countries"])
    ) 
  )
)->findAll(array('select' => 'question'));

这没关系,直到 POST 中的所有数据都不是数组。

我想更改 POST 以返回一个数组。现在,当我从视图中返回 $_POST['Questions']['categories'] 作为数组时,如何编写 Questions::model() 的标准。

我收到通知:

Array to string conversion: this->_statement->bindValue($name, $value, $this->_connection->getPdoType(gettype($value)));

那么,什么是正确的方法呢?:)

- 帖子的代码(来自视图)

CHtml::activeCheckboxList($model, 'countries'CHtml::listData(Countries::model()->findAll(), 'id', 'name'), array('template'=>'<li>{input} {label}</li>',));
$form->dropDownList($model, 'categories', 
                  CHtml::listData(Categories::model()->findAll(), 'id', 'name'),
                  array('prompt' => 'Select category')
            );

如果您需要更多信息,还有我以前的帖子,这是继续看帖子

4

1 回答 1

0

Well I'm not that good with joins, but I would try something like:

$model = Questions::model()->with( 
  array( 
    'categories' => array (
      'select' => 'name',
    ),
    'countries' => array (
      'select' => 'name',
      'condition' => 'countries.id=:cou_id',
      'params' => array (':cou_id' => $_POST["Questions"]["countries"])
    ) 
  )
)->findAllByAttributes(
    array('categories.id' => $_POST["Questions"]["categories"]), 
    array('select' => 'question'));

Although I don't think this will return what you want it to.

于 2013-09-13T10:19:27.770 回答