cakephp-3.0

Cakephp 3 dynamic validation error messages

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:18:33
问题 I'm validating file uploads in my form and i want to know if it's possible to display a dynamic message using information from the form. This is my validation model: public function validationDefault(\Cake\Validation\Validator $validator) { $validator ->allowEmpty('file') ->add('file', array( 'extension'=>array( 'rule' => ['extension', ['jpeg', 'png', 'jpg']], 'message' => '[[fileName]] has no valid extension.' ), 'fileSize' => array( 'rule' => array('fileSize', '<=', '100K'), 'message' => '[

CakePHP 3: change order in dateWidget

情到浓时终转凉″ 提交于 2019-12-11 04:00:40
问题 I found on the CakePHP developer's guide the following hint on how to adjust the order of the fields when using the date form input. It says To control the order of inputs, and any elements/content between the inputs you can override the dateWidget template. However, I cannot find anywhere a hint on how to change the order and use this in a view. Can you give hints? 回答1: You can configure the DateWidget template when initializing the Form helper // in MyController.initialize() $this-

How to save associated joinData in cakephp 3.x

安稳与你 提交于 2019-12-11 03:52:34
问题 I have Problems and Fields in a many-to-many relationship. The join table fields_problems has a field named fieldvalue I am trying to have a form that will insert a problem record and also multiple records into fields_problems. /src/Model/Table/ProblemsTable.php class ProblemsTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->table('problems'); $this->displayField('id'); $this->primaryKey('id'); $this->addBehavior('Timestamp'); $this-

Cakephp 3.x Custom Query Pagination

≡放荡痞女 提交于 2019-12-11 03:49:37
问题 I used in Cakephp 2.x Custom Query Pagination. Now I am trying to migrate a project to Cake 3. The manual of Cake 3 does not mention Custom Query Pagination any more, and it seems, that the model function paginate / paginateCount which are used for the Custom Query Pagination are not called. Does anyone know, if this is dropped in Cake 3 ? If so, how can I do pagination with custom queries in cake 3 ? 回答1: Try this: public function index() { $query = $this->Articles->find('popular')->where([

custom finder with matching in association definition?

允我心安 提交于 2019-12-11 02:36:30
问题 I have two models: Contacts and Groups with belongsToMany association. I want to get only that groups what is accessible for the contact. For this I have a custom finder. public function findAccessible(Query $query, array $options){ return $query ->where(['admin_user_id' => $options['User.id']]) ->orWhere(['public' => true]) ->matching('Users', function($q) use ($options){ return $q->orWhere(['Users.id' => $options['User.id']]); }); } So I can call to following and I will get what I want.

cakephp 3 queryBuilder for associative data

冷暖自知 提交于 2019-12-11 01:49:08
问题 I have 2 tables. Table 1: product_prices: id | price |description |pack |display |created |modified | Table 2: payment_infos: id |payer |pay_date |product_price_id |product_price | In the payment_infos model $this->belongsTo('ProductPrices', [ 'foreignKey' => 'product_price_id', 'className' => 'ProductPrices', ]); I have this query: $query = $this->find('all', [ 'contain' => ['ProductPrices'] ])); When running the above query I get the following error: Warning (512): Association property name

CakePHP 3.0 not running without intl extension

久未见 提交于 2019-12-11 01:45:33
问题 I am trying to install and run a CakePHP 3.0 project on a shared host. However, CakePHP 3.0 requires php-intl extension, but the hosting provider has denied me to install/enable intl extension on the shared hosting. How can I run CakePHP 3.0 without intl extension ? Is there anyway to disable it in CakePHP? Or is there any alternative that I can use ? I am into a big trouble. Please help... 回答1: if there are still problem to install php_intl, try next plugin: https://github.com/hraq/cake-intl

SUM query in cakephp 3 not working

…衆ロ難τιáo~ 提交于 2019-12-11 01:22:12
问题 I am trying to add the data of same field and want to return a result i used the following query: $total = $this->Details->find('all', array( 'fields' => array('sum(Details.total_downtime+ Details.total_downtime)'), 'conditions' => array('Details.site_id' => $id) )); print_r($total->toArray()); exit; And I am getting the following result: Array ( [0] => App\Model\Entity\Detail Object ( [displayField] => username [_accessible:protected] => Array ( [*] => 1 [id] => 1 [site_id] => 1 [uptime] =>

CakePHP3: How can I do text searching using full-text indexes

梦想与她 提交于 2019-12-11 00:53:56
问题 I used the below code to search using full-text indexes $query = $this->Posts->find() ->contain(['Categories' ]) ->where([ 'MATCH(Posts.title) AGAINST(? IN BOOLEAN MODE)' => $search ]); But I got the below error SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters Please advise Thanks in advance! 回答1: Try rewriting your query as: $query = $this->Posts->find() ->contain(['Categories']) ->where([ "MATCH(Posts.title) AGAINST(:search IN BOOLEAN MODE)" ]) ->bind('

Scheduled Task on CakePHP

孤者浪人 提交于 2019-12-10 19:35:14
问题 I work on CakePHP 3.2 Project.. I have a Property Entity.. when a user creates a property , the admin must validate it to become active .. After that I put in field called date_of_expiration the current date + 10 days for example ... What I want is that this property expires in this date (current date + 10 day).. By changing a field called status from active to inactive .. I searched in Google and i found that what i nead called Sheduled Task .. I ask about the best way to do this in CakePHP