cakephp error: unexpected '(', expecting ')', is my syntax wrong? - syntax

Do you see any syntax errors here?
'Coupon'=>array(
'fields'=>array(
'promo_code','desc'
),
'conditions'=>array(
'OR'=>array(
'expires' =>0,
'Coupon.end_date >'=>date('Y-m-d')
)
)
),
This is part of my 'contain' array in my controller code. When I remove this snippet from my code, cake works great (only I need this part!). Am posting the entire statement below. Help?
public $paginate = array(
'Location'=>array(
'joins' => array(
array(
'table' => 'locations_tags',
'alias' => 'LocationsTag',
'type' => 'inner',
'conditions'=> array(
'LocationsTag.location_id = Location.id'
)
)
),
'limit'=>9,
'contain'=>array(
'Course'=>array(
'fields'=>array(
'specials', 'contact','desc'
),
'conditions'=>array('Course.active'=>1)
),
'Charter'=>array(
'fields'=>array(
'book','specials', 'contact','desc'
),
'conditions'=>array('Charter.active'=>1)
),
'Restaurant'=>array(
'fields'=>array(
'menu','wine_list','specials', 'contact','desc'
),
'conditions'=>array('Restaurant.active'=>1)
),
'Nightclub'=>array(
'fields'=>array(
'menu','schedule','specials', 'contact','desc'
),
'conditions'=>array('Nightclub.active'=>1)
),
'Store'=>array(
'fields'=>array(
'catalog','specials', 'contact','desc'
),
'conditions'=>array('Store.active'=>1)
),
'Coupon'=>array(
'fields'=>array(
'promo_code','desc'
),
'conditions'=>array(
'OR'=>array(
'expires' =>0,
'Coupon.end_date >'=>date('Y-m-d')
)
)
),
'Image',
'Tag'=>array(
'fields'=>array(
'seo_tag'
)
)
)
)
);

'Coupon.end_date >'=>date('Y-m-d')
You can't assign calculated values (e.g., calling functions) in class property declarations. They have to be constant values.
For a calculated value, you'd have to assign that in the constructor or something.
From the docs:
This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

Related

Nuxt color-mode SassError: argument `$color` of `lightness($color)` must be a color

My Nuxt SSR project uses Bulma/Buefy and I am trying to use the #nuxtjs/color-mode module with it
Here is my vars.scss file where I define the light-mode and dark-mode classes
// Import Bulma's core
#import '~bulma/sass/utilities/_all';
$primary-light-color: #0075f2;
$primary-dark-color: #0015f2;
html {
&.light-mode {
--primary-color: #{$primary-light-color};
}
&.dark-mode {
--primary-color: #{$primary-dark-color};
}
}
// Set your colors
$white: #fdfffc;
$black: #272932;
$primary: var(--primary-color);
$primary-invert: findcolorinvert($primary);
$link: #004ba8;
$link-invert: findcolorinvert($link);
$info: #00b4d8;
$info-invert: findcolorinvert($info);
$success: #4cb944;
$success-invert: findcolorinvert($success);
$warning: #ffba08;
$warning-invert: findcolorinvert($warning);
$danger: #f06543;
$danger-invert: findcolorinvert($danger);
$facebook: #3b5998;
$facebook-invert: findcolorinvert($facebook);
$twitter: #4099ff;
$twitter-invert: findcolorinvert($twitter);
$google: #dd4b39;
$google-invert: findcolorinvert($google);
$github: #333;
$github-invert: findcolorinvert($github);
// Setup $colors to use as bulma classes (e.g. 'is-twitter')
$colors: (
'white': (
$white,
$black,
),
'black': (
$black,
$white,
),
'light': (
$light,
$light-invert,
),
'dark': (
$dark,
$dark-invert,
),
'primary': (
$primary,
$primary-invert,
),
'info': (
$info,
$info-invert,
),
'success': (
$success,
$success-invert,
),
'warning': (
$warning,
$warning-invert,
),
'danger': (
$danger,
$danger-invert,
),
'facebook': (
$facebook,
$facebook-invert,
),
'twitter': (
$twitter,
$twitter-invert,
),
'google': (
$google,
$google-invert,
),
'github': (
$github,
$github-invert,
),
);
$navbar-height: 3.5rem;
// https://bulma.io/documentation/components/pagination/#variables
// Removed to make the pagination at the bottom of any table appear without vertical scrollbar
$pagination-margin: 0;
It gives me the following error
ERROR in ./assets/app.scss (./node_modules/css-loader/dist/cjs.js??ref--7-oneOf-1-1!./node_modules/postcss-loader/src??ref--7-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--7-oneOf-1-3!./node_modules/sass-resources-loader/lib/loader.js??ref--7-oneOf-1-4!./assets/app.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: argument `$color` of `lightness($color)` must be a color
on line 58 of node_modules/bulma/sass/components/message.sass, in function `lightness`
from line 58 of node_modules/bulma/sass/components/message.sass
from line 10 of node_modules/bulma/sass/components/_all.sass
from line 7 of node_modules/bulma/bulma.sass
from line 101 of assets/app.scss
>> $color-lightning: max((100% - lightness($color)) - 2%, 0%);
------------------------------------^
Here is my link to CodeSandbox Can someone kindly tell me how to fix this?
You are passing a var() ($primary: var(--primary-color);) instead of a color (HEX, HSL, RGB, etc).
I ran into a similar problem and got the same Error: SassError: argument '$color' of 'lightness($color)' must be a color.
found out that according to #PirateApp this error occurs because we gave to lightness() method a variable "that references to another variable instead of a color" as an argument.
this means that we can provide a variable as an argument, only if our variable references to a color. So the solution I came up with, is a little trick;
When defining a variable, make it as an adjusted color, instead of referencing to another variable.
so instead of this:
'white': (
$white,
$black,
),
we can write it this way:
'white': (
adjust-hue($white,0deg),
adjust-hue($black,0deg),
),

Google Drive API get files in specific folder in Laravel

i am using the following code to get files from folder id. But I am not getting the files id instead empty array returning.
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\Users\new\Downloads\zonefunnel1.json');
$client = new Google_Client();
$client->addScope(Google_Service_Drive::DRIVE);
$client->useApplicationDefaultCredentials();
$service = new Google_Service_Drive($client);
$res=$service->files->listFiles();
//print_r($res);
$folderId="0B_bZZilaXPR4WkNvdFpMZmdneEU";
$optParams = array(
'pageSize' => 10,
'fields' => "nextPageToken, files(contentHints/thumbnail,fileExtension,iconLink,id,name,size,thumbnailLink,webContentLink,webViewLink,mimeType,parents)",
'q' => "'".$folderId."' in parents"
);
$results = $service->files->listFiles($optParams);
print_r($results);die();
I am getting the following,
Google_Service_Drive_FileList Object ( [collection_key:protected] => files [filesType:protected] => Google_Service_Drive_DriveFile [filesDataType:protected] => array [incompleteSearch] => [kind] => [nextPageToken] => [internal_gapi_mappings:protected] => Array ( ) [modelData:protected] => Array ( ) [processed:protected] => Array ( ) [files] => Array ( ) )
Please help me I have spent one week time for this.But not able to sort it out.
Regards,
Rekha
$files_list = $service->files->listFiles(array())->getFiles($optParams);

For In Grammar Breaking Identifiers

I'm trying to make a syntax highlighter in Atom for a toy language I'm working on. I'm at the stage where I'm defining the context free grammar. I've been building it up step by step and writing tests along the way. When I added the grammar for a for in loop it broke my test for parsing identifiers because the identifier started with "in". Here's the grammar as it stands now (Sorry for pasting so much code but I didn't know what might be relevant so I just added the whole thing):
module.exports = grammar({
name: 'MooLang',
rules: {
source_file: $ => repeat($._declaration),
_declaration: $ => choice(
$.variable_declaration,
$._statement
),
variable_declaration: $ => seq(
choice('var', 'let'),
$.identifier,
optional(seq(
':', $._type
)),
optional(seq(
'=', $._expression
)),
$.eol
),
_statement: $ => choice(
$.for_statement,
$.expression_statement
),
for_statement: $ => prec(0, seq(
'for',
'(',
choice(
$.variable_declaration,
$.expression_statement,
),
'in',
$._expression,
')',
$._statement
)),
expression_statement: $ => prec(1, seq(
$._expression,
$.eol
)),
_expression: $ => choice(
$.assignment,
$.comparison_expression,
$.addition_expression,
$.multiplication_expression,
$.unary_expression,
prec(5, $.primary),
prec(-1, $._type) // TODO:(Casey) Remove this
),
assignment: $ => prec.right(0, seq(
$.identifier,
'=',
$._expression
)),
comparison_expression: $ => prec.left(1, seq(
$._expression,
choice('<', '<=', '>', '>=', '==', '!='),
$._expression
)),
addition_expression: $ => prec.left(2, seq(
$._expression,
choice('+', '-'),
$._expression
)),
multiplication_expression: $ => prec.left(3, seq(
$._expression,
choice('*', '/', '%'),
$._expression
)),
unary_expression: $=> prec.right(4, seq(
choice('!', '-'),
$.primary
)),
_type: $ => choice(
$.primitive_type,
$.list_type,
$.map_type
),
primitive_type: $ => choice(
'bool', 'string',
'int8', 'int16', 'int32', 'int64',
'uint8', 'uint16', 'uint32', 'uint64',
'float32', 'float64'
),
list_type: $ => seq(
'[',
$._type,
']'
),
map_type: $ => seq(
'{',
$._type,
':',
$._type,
'}'
),
primary: $ => choice(
$.bool_literal,
$.list_literal,
$.map_literal,
$.parenthetical_expression,
$.identifier,
$.number
),
bool_literal: $ => choice('true', 'false'),
list_literal: $ => seq(
'[',
optional(seq(
$._expression,
repeat(seq(
',',
$._expression
)),
optional(','),
)),
']'
),
map_literal: $ => seq(
'{',
optional(seq(
$._expression,
':',
$._expression,
repeat(seq(
',',
$._expression,
':',
$._expression,
)),
)),
'}'
),
parenthetical_expression: $ => seq(
'(',
$._expression,
')'
),
identifier: $ => prec(99, /[a-zA-Z_][a-zA-Z0-9_]*/),
number: $ => prec(99, /\d+(_\d+)*(\.\d+)?/),
eol: $ => '\n'
}
});
Here are the relevant tests:
==================
Identifier Tests
==================
13india
---
(source_file
(expression_statement (primary (number)) (MISSING))
(expression_statement (primary (identifier)) (eol))
)
==================
For Tests
==================
for (var a in people) a + 1
---
(source_file
(for_statement (variable_declaration (identifier)) (primary (identifier)) (expression_statement (addition_expression (primary (identifier)) (primary (number))) (eol)))
)
Until I added the grammar for the for loop all of the Identifier Tests were passing but now I get this output:
My guess is that it finds an unexpected 'd' because it thinks this is the 'in' keyword. But I can't figure out why it would think that since it doesn't match anything else about the for loop.

Query error in code igniter ( wrong escape )

I try to insert a row in the table on code igniter from a Array, but something is going wrong.
That's the array:
Array
(
[Date] => 2001-08-15
[Number] => 962883
[Time] => 17:40
[Etc1] => 0
[Etc2] => 0
)
And this the insert:
$this->db->insert('mytable', $myarray);
A new line is inserted, but all columns are empty!
Trying to find de error, I printed the last query by
echo $this->db->last_query() ." <br>";
And I got:
INSERT INTO `mytable` (`Date`, `Number`, `Time`, `Etc1`, `Etc2`)
VALUES
('\02\00\00\01\0-\00\08\0-\01\05\0', '\09\06\02\08\08\03\0', '\01\07\0:\04\00\0', '\00\0', '\00\0')
For some reason I can not get, the codeigniter ( or PHP ) is wrongly escaping the values.
Any Idea?
Firstly your change your array like this:
$data_array = Array
(
'Date'=> 2001-08-15
'Number' => 962883
'Time' => 17:40
'Etc1' => 0
'Etc2' => 0
);
$this->your_model->insert_data($data_array);
and inside your model write function like this
function insert_data($data=array())
{
$this->db->trans_start();
$this->db->insert('your_table_name',$data);
$this->db->trans_complete();
return TRUE;
}
i hope this will solve your problem
try this , this may help.
$this->db->set('Date', '2001-08-15', FALSE);
$this->db->set('Number', '962883', FALSE);
$this->db->set('Time', '17:40', FALSE);
$this->db->set('Etc1', '0', FALSE);
$this->db->set('Etc2', '0', FALSE);
this->db->insert('mytable');
I tried emulating your problem and was able to get the correct SQL statement genrated.
But I am pasting here the code that worked for me:
$data = array
(
'Date' => '2001-08-15',
'Number' => '962883',
'Time' => '17:40',
'Etc1' => '0',
'Etc2' => '0'
);
$this->db->insert('mytable', $data);
Let me know if this works - and if not, what the error message is.

Zend Framework Validate field is integer between 1 and 5

I use Zend\InputFilter\InputFilter class for form validation. point field should accept only integers between 1 and 5. But it doesn't work properly it accepts string starting with integers between 1 and 5. For example 1kjhkjh, 2tgfjhgfjhf, 4jhkljg...
What is wrong in my code?
$inputFilter->add (
$inputFilter->getFactory()->createInput (
array (
'name' => 'point',
'required' => true,
'validators' => array (
array(
'name' => 'Digits'),
array (
'name' => 'Between',
'options' => array (
'min' => 1,
'max' => 5,
'messages' => array('notBetween' => 'Point must be between %min% and %max%')
)
)
)
)
)
);
Use the the second parameter of zend validator to break the validators chain and return an error, breakChainOnFailure (documentation) tells the element to stop validating if this error is triggered, so in your case if it is not a digit the user gets an error, when the user has fixed the error the second validator will get triggered too:
$inputFilter->add (
$inputFilter->getFactory()->createInput (
array (
'name' => 'point',
'required' => true,
'validators' => array (
array(
'name' => 'Digits', 'breakChainOnFailure' => true),
array (
'name' => 'Between',
'options' => array (
'min' => 1,
'max' => 5,
'messages' => array('notBetween' => 'Point must be between %min% and %max%')
)
)
)
)
)
);
Another option would be to replace Zend_Validate_Digits with Zend_Validate_Int (docmentation) depending of what error message you prefer to give to the user if he enters non valid data. Of course as suggested in the comments you could also use the Zend_Filter_Int if what you want is to handle any non valid data by fixing it yourself and do not give the user feedback about what he did wrong.
'breakChainOnFailure': true
should be
'breakChainOnFailure'=> true

Resources