CakePHP 3.x remove field from validation - cakephp-3.4

Is there a simple way to ignore a filed from being validated in CakePHP 3.x Controller?
I know two ways: First one is specify fieldListin patchEntity
second one is use validate => myCustomValidater
I do not want to use none of them, is there a simple method ?

Related

Shopware 6 add entity extension fields to admin search

I wonder how to make some fields of an entity extension searchable in the administration through the "/api/search/my-entity" api-endpoint. By default they are not considered during search as it looks like.
I found the answer by debugging the search-endpoint:
The association-Field of the EntityExtension needs to have a SearchRanking-flag:
...->addFlags(new SearchRanking(SearchRanking::ASSOCIATION_SEARCH_RANKING))
Then you can add SearchRanking-flags in the EntityExtensionDefinition as you like, e.g.:
(new StringField('test', 'test'))->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
After that the fields are searchable via the search-endpoint :)
As far as the API is concerned, search functionality should automatically be generated following your custom entity definitions.
When it comes to facilitate Admin search for your entity, you need to add some code to the administration component as described in the docs: https://developer.shopware.com/docs/guides/plugins/plugins/administration/search-custom-data (even though it looks not fully up-to-date w.r.t to the current Shopware versions).

Is there a way to make Prestashop's Layared Filter Module to use query parameters instead of anchors (hashes)?

Is there any way to make the standart PrestaShop's Layered filters module to use URL parameters instead of anchors (the part after hash)?
I ment that I want the layered filter generate and accept the URLs like this (or maybe somehow diferrent, but the key is to use parameters and not to use hashes):
my-example-shop.ru/some-category/?color=red&size=xl
instead of this:
my-example-shop.ru/some-category#/color-red/size-xl
The reason is that the most of advertisment systems could add some parameters to the URL, but they usuaul add it directly to the end of the URL, and dont trying to analyze url structure and insert parameters to the right place.
So, as far as i see, the obvious solution is to avoid using hashes in url, using just query parameters, and to use history.pushState to change URL without refreshing whole page...
It seems obvious, usable, but I cant find any ready-to-use solution that do this such way, and I cant find even information about how does someone did it..
So the questions are:
is there any ready-to-use solution?
is there any described way to reach this by myself?
Thanks in advance.
UPD
All I found by myself for now is that such URLs could be accepted:
my-example-shop.ru/some-category/color-red/size-xl
my-example-shop.ru/some-category?selected_filters=/color-red/size-xl
BUT any filters changing causes using hashes again (afaik, hashed filters values overrides values passed via selected_filters parameter, so subsequent navigation just ignores selected_filters). In other words - I just can clear the entry URL, BUT I couldnt make URLs to be clean for subsequent navigation.
The change is very large.
You should create the override classes/Dispatcher.php
For filters instead you should edit the file: blocklayered/blocklayered.php
find function: getSelectedFilters()
Inside are two foreach, you should withdraw from the url "featured" fields that you need and compile the new array "$selected_filters"

How to get PATCH parameters of REST API in Yii 1.1?

Yii 1.1.16 brought getPatch($paramName, $defaultValue=null) and getIsPatchRequest() to life, but is there a way to loop through all PATCH parameters, without knowing their names? If a user wants to modify his tag line, but nothing else, how am I supposed to know that he wants to change user_tag_line?
Calling getPatch() gives
Missing argument 1 for CHttpRequest::getPatch().
I've solved it by using
CJSON::decode(file_get_contents('php://input'));
Is this safe, should this be used? Are there other ways of going about this?

Kohana 3 auth username as number

I want to use numbers as username in Kohana Auth. For example, username 100001?
While adding new user Kohana returns me error: ORM_Validation_Exception [ 0 ]: Failed to validate array
Is is possible to user numbers as username in Kohana?
EDIT: This answer looks simpler and better than mine, but try to understand it at all.
You need to extend User Model, I'll help you using auth with the ORM driver.
Steps to extend User Model:
If you didn't yet, configure Auth module to use orm and create a database table with the fields you want. Here is a good example of how to doing it (It's an old tutorial using ko3.1 but you can still learn from it). PS.: you can have any columns at the 'users' table and you don't need to have the 'username' column if you do not want.
Open and read carefully this file: MODULES/orm/classes/model/auth/user.php (It's self documented and I hope you understand it. If not, stop reading this answer here and read the kohana docs. Some shortcuts: Auth - Kohana User Guide, Auth (orm) methods, addons:auth
Copy the file (don't edit the original) to APPPATH/classes/model/auth/user.php and edit it how you want. Some functions that you may like to edit are: rules, filters and unique_key (<- useful). Be creative, you also can add custom functions.
Test and change whatever else needed.
You can change the login method to works as you like. You can set login by e-mail, make a custom validation method or parse values before saving in the database (see public function filters()). This is helpful for whatever you try to do with auth module using ORM... But... if you really don't want to use ORM, you can build your own driver, learn how.
I made this some time ago in kohana 3.2 but I think you won't get problems with 3.3. If you still have questions, this question on kohana forum may help.

What is the Rails way to handle adding a required attribute on an existing model

For example, I recently added 'address' fields to my user model. They are being validated by presence. So now, when I went to update a different attribute, email for example, I can't save the user because it has invalid fields (the address is still blank).
Do you just have to migrate the data with blank strings or something?
What is the Rails way to handle this?
One way to handle this is to populate the new field in the migration which creates it. That way, you're ensuring that everything in the database is valid according to the model. The guide has some pointers on doing this - there are a couple of gotchas.
Another way is by specifying that the validation only runs on creation, not on updates, with the :on option. That might look like:
validates :address, :presence => true, :on => :create
That way, any new user has to have the address set, but you're still able to edit other attributes on existing users.
I suggest you do the migration every time you add new fields and put validations on them.
It would keep the data integrity and consistency.
If you really want to do a trick, adding conditions on validation, putting "validate: false" conditionally when you do save, adding blank value for address fields when you modify an existing records all are tricks you can use.
I also suggest that when you add address, create a address model and share it among other models which need it, instead of only adding fields into the models. That would make your validation more flexible.