miércoles, 4 de marzo de 2020

allowEmptyString() - Means allow only an empty string or a populated string and an empty string

CakePHP Version: 4.0.1 // Introduction I need to validate my grade select list so it accepts an empty string or a populated string. --- I'd like to check my interpretation of the following sentence which can be found here. allowEmptyString() Should be used when you want to only accept an empty string. Does this mean I should only use this function when I ONLY want to accept an empty string or when I want to accept an empty string or a populated string. The reason I'm asking is because when I use allowEmptyString() it negates the displaying of --Select-- in my select lists. Please see below: // Markets Add View $options = [ '' => '--Select--', // THIS IS WHAT IS NOT DISPLAYED WHEN I USE allowEmptyString() IN THE MARKETS TABLE VALIDATOR. 'A' => 'A', 'B' => 'B', 'C' => 'C', 'D' => 'D', 'E' => 'E' ]; echo $this->Form->control('grade', [ 'type' => 'select', 'options' => $options, 'class' => 'ns-std std', 'autocomplete' => 'off', 'label' => false ]); // Markets table default validator ->scalar('grade') ->allowEmptyString('grade') // IF I COMMENT THIS LINE THE --Select-- OPTION IS DISPLAYED. ->add('grade', 'validGrade', [ 'rule' => 'isValidGrade', 'message' => __('Invalid grade!'), 'provider' => 'table' ]) --- If I make a literal interpretation of the sentence it means to me that I should NOT use this function in the validator because the grade select list can except a populated string OR an empty string and the sentence reads 'only accept an empty string' But before I go ahead and delete all references to allowEmptyString() in my validators where appropriate I thought I'd check. Also by default this would mean that there is no check for a empty or populated string. --- // My Question Is my interpretation of the sentence correct and I should NOT use this function because I want to accept an empty OR a populated string. Thanks Zenzs. --- EDIT Salines... // Markets Add View echo $this->Form->select( 'grade', ['A', 'B', 'C', 'D', 'E'], [ 'empty' => '--Select--', 'class' => 'ns-std std', 'autocomplete' => 'off', 'label' => false ], ); // Markets table default validator ->scalar('grade') ->allowEmptyString('grade') The above method all works and I now validate successfully for an empty string and a populated string. I'll have to create a new custom validation rule as 0, 1, 2, 3 and 4 instead of A, B, C, D and E are inserted into the database and a cell to handle the conversions in the view but that's no problem. I'll have to do that tommorrow though as I've run out of time today.
http://dlvr.it/RRG5g8

New code snippet for bootstrap framework #bootstrap #bootstrap4 #framework #html #css #webdesigner #webdeveloper #WebDevelopment #webdesign

bs4 event timeline
http://dlvr.it/RRDdZh

martes, 3 de marzo de 2020

Issues with display FK Data in CakePHP

I'm trying to display the actual value as opposed to the ID Number using cakePHP. These are my Tables Roles Table Users Table l This is my UsersTable code class UsersTable extends Table { public function initialize(array $config) { $this->hasOne('Roles'); } This is my UsersController code public function list() { $usersTable = $this->Users->find('all')->contain(['Roles']); $allUsers = $usersTable->toArray(); $this->set("allUsers", $allUsers); } This is how im trying to print it $user->role->name However I am getting the following error Error What am I doing wrong and how do I fix this issues?
http://dlvr.it/RRBM4d

Nginx conf erratic behaviour with Cakephp

I try to access to my cakephp project with my nginx config file. I have a 404 page not found with this config : root /app; index index.php; location /--redacted--/webroot/ { index index.php index.html index.htm; if (-f $request_filename) { break; } if (-d $request_filename) { break; } rewrite ^(.+)$ /index.php?q=$1 last; } After reading multiples solutions, on multiple websites, I tried to put it as root and my index page works. Nginx config file looks like that then : root /app/--redacted--/webroot; index index.php; location / { index index.php index.html index.htm; if (-f $request_filename) { break; } if (-d $request_filename) { break; } rewrite ^(.+)$ /index.php?q=$1 last; } The rest of the config file is the same in the cases. I search to understand why the behaviour of Nginx is so erratic. Why the first case doesn't work ? (Sorry if this is a repeated question ^^')
http://dlvr.it/RR9QBX

martes, 18 de febrero de 2020

New code snippet for bootstrap framework #bootstrap #bootstrap4 #framework #html #css #webdesigner #webdeveloper

Simple email inbox page
http://dlvr.it/RQHxXM

New code snippet for bootstrap framework #bootstrap #bootstrap4 #framework #html #css #webdesigner #webdeveloper

bs4 Email alert
http://dlvr.it/RQHxVx

Cakephp 3 query with conditions array build in foreach loop

Hello i want to use an array as condition. For example i have services with a zip as combination 12345 => cleaning, 54321 => cleaning now i build my array together in a foreach loop $searcharray = []; foreach($services as $key => $val){ searcharray[] = array('service' => $val['service'], 'zip' => $val['zip']); } My search array lookes like this: [ (int) 0 => [ 'service' => 'cleaning', 'zip' => '12345' ], (int) 1 => [ 'service' => 'cleaning', 'zip' => '54321' ] ] Then i try to get the data from my request table $this->loadModel('Requests'); $openrequests = $this->Requests->find('all', array( 'conditions' => array( 'OR' => array( $searcharray ) ) )); It didnt work maybe of the keys in the array, because i set after the $searcharray for example [1] and then it works. I dont want to write the condition as string, but how can i solve it?
http://dlvr.it/RQHwxc