我安裝了Dc搜索插件。我在交易頁面上應用這個插件,它可以正常工作。 但在聯繫索引頁上它不起作用。在這兩個頁面上的區別是聯繫頁面包含多個表,如公司,company_contacts,單位,稅收等等的關係。但在交易頁面數據只來自交易表。另外,這兩者都沒有區別。第二個是作爲聯繫人索引頁面的模型,我使用company.php而不是contact.php。Dc搜索框插件不能在cakephp中工作?
在我的index.php
<?php if(!empty($search_args['search_cname'])): ?>
<strong><?php echo __('Company Name:'); ?> </strong><span><?php echo $search_args['search_cname']; ?></span>
<?php endif; ?>
<?php if(!empty($search_args['search_name'])): ?>
<strong><?php echo __('Contact Person:'); ?> </strong><span><?php echo $search_args['search_name']; ?></span>
<?php endif; ?>
<?php if(!empty($search_args['search_status'])): ?>
<strong><?php echo __('Status:'); ?> </strong><span><?php echo $search_args['search_status']; ?></span>
<?php endif; ?>
<?php if(!empty($search_args['search_uname'])): ?>
<strong><?php echo __('User Name:'); ?> </strong><span><?php echo $search_args['search_uname']; ?></span>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="filter-box" style="display:none">
<?php echo $this->Form->create('company', array('url' => array_merge(array('controller'=>'contacts','action' => 'index'), $this->params['pass']),'class'=>'form-inline')); ?>
<fieldset>
<legend><?php echo __(Filters); ?></legend>
<?php echo $this->Form->input('search_status',array('div'=>false,'class'=>'span2','options'=>array(4=>'Lead',5=>'Opportunity',6=>'Account'),'label'=>'Status ',)); ?>
<?php echo $this->Form->input('search_cname',array('div'=>false,'class'=>'span2','label'=>'Company Name ','placeholder'=>'Company Name')); ?>
<?php echo $this->Form->input('search_name',array('div'=>false,'class'=>'span2','label'=>'Contact Person ','placeholder'=>'Contact Person')); ?>
<?php echo $this->Form->input('search_uname',array('div'=>false,'class'=>'span2','label'=>'User Name ','placeholder'=>'User Name')); ?>
<?php echo $this->Form->submit('Filter',array('div'=>false,'class'=>'btn btn-info')); ?>
</fieldset>
<?php echo $this->Form->end(); ?>
</div>
在ContactController.php
$searched = false;
if ($this->passedArgs) {
$args = $this->passedArgs;
if(isset($args['search_cname'])){
$searched = true;
}
if(isset($args['search_name'])){
$searched = true;
}
}
$this->set('searched',$searched);
在型號contact.php
public $actsAs = array(
'Search.Searchable',
);
public $filterArgs = array(
'search_status' => array('type'=>'value','field'=>'company.contact_status_id'),
'search_cname' => array('type'=>'like','field'=>array('company.company_name')),
'search_name' => array('type'=>'like','field'=>array('company_contacts.first_name','company_contacts.last_name')),
'search_uname' => array('type'=>'like','field'=>'User.full_name'),
'search_all' => array('type'=>'query','method'=>'searchDefault')
);
public function searchDefault($data = array()) {
$filter = $data['search_all'];
$cond = array(
'OR' => array(
// 'company.company_name LIKE' => '%' . $filter . '%',
'company_contacts.first_name LIKE' => '%' . $filter . '%',
'company_contacts.last_name LIKE' => '%' . $filter . '%',
'company_contacts.email LIKE' => '%' . $filter . '%',
'company_contacts.mobile_number LIKE' => '%' . $filter . '%',
$this->alias . '.company_name LIKE' => '%' . $filter . '%',
'User.full_name LIKE' => '%' . $filter . '%',
// $this->alias . '.first_name LIKE' => '%' . $filter . '%',
// $this->alias . '.last_name LIKE' => '%' . $filter . '%',
// $this->alias . '.status LIKE' => '%' . $filter . '%'
));
return $cond;
}
我嘗試這一點,但它吉斯以下錯誤 –
我試試這個。但不幸的是它給出了以下錯誤錯誤:調用未定義的方法PrgComponent :: parsedParams() File:C:\ xampp \ htdocs \ salescrm \ app \ Controller \ ContactsController.php Line:51 注意:定製這個錯誤信息,創建應用程序\視圖\錯誤\ fatal_error.ctp –
好吧,得到你點 請用$ this-> passedArgs取代$ this-> Prg-> parsedParams()並重試。讓我知道如果仍然不工作 –