Cakephp, 멀티 선택 상자에 대한 복잡한/다중 찾기 조건 설정
-
18-09-2019 - |
문제
제조업체 이름이라는 다중 선택 상자가 올바르게 표시되고 있으며 멀티 검색을 위해 클릭 할 수 있습니다. 검색을 실행할 때 설정 한 복잡한 찾기 조건을 사용하여 데이터베이스에서 결과를 얻지 못합니다. 나는 빵집과 다른 다양한 웹 사이트에서 복잡한 고정 조건을 사용하려고 노력했지만 소용이 없습니다.
//This my index.ctp
<?=$form->create('ManufacturersProductsLine', array('action'=>'index'));?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<?=$f->label('ManufacturersProductsLine.manufacturer_id', 'Manufacturer Name:'); ?>
<?=$f->select('ManufacturersProductsLine.manufacturer_id', $manufacturers, null, array('multiple'=>'multiple', 'style'=>'height:100px;'))?>
</td>
<td>
<?=$f->label('ManufacturersProductsLine.name', 'Product Name:'); ?>
<?=$f->text('ManufacturersProductsLine.name', array('style'=>'width:140px;'));?>
</td>
<td>
<label></label>
<input name="Search" class="blue" type="submit" value="Search Product Lines" />
</td>
</tr>
</table>
여러 가지 찾기 조건을 설정하기 위해 컨트롤러에서 시도한 것들이 댓글을 달았습니다.
//This is my manufacturers_products_lines_controller.php
function index() {
$conditions = array();
if (!empty($this->data)) {
$data = $this->data;
$conditions[] = "(LOWER(ManufacturersProductsLine.manufacturer_id) LIKE '%{$data['ManufacturersProductsLine']['manufacturer_id']}%')";
//$conditions = array("ManufacturersProductsLine.name" => array("Akuret", "Bridgestone", "American Radials") );
debug($this->data);
}
$this->Manufacturer->recursive = 1;
$this->set('manufacturersproductslines', $manufacturersproductslines = $this->paginate('ManufacturersProductsLine', $conditions));
$Manufacturer = getModel('Manufacturer');
$this->set('manufacturers', $Manufacturer->find('list'));
//$this->ManufacturersProductsLine->recursive = 0;
//$this->Post->find('all', array('conditions' => array('ManufacturersProductsLine.manufacturer_id' =>array(0,1,2,3,4,5,6,7,8,9,10,11,12,13))));
}
디버그하고 검색 할 때 다음을 받고 있습니다.
Array
(
[ManufacturersProductsLine] => Array
(
[manufacturer_id] => Array
(
[0] => 1
[1] => 2
)
[name] =>
)
)
해결책
이로 쿼리 조건을 변경해보십시오
$conditions[] = "ManufacturersProductsLine.manufacturer_id IN (" . implode( ',', $data['ManufacturersProductsLine']['manufacturer_id'] . ")";
제휴하지 않습니다 StackOverflow