This is my original code
new Data({ data_id: #model.get 'id' })
.fetch()
.done (result) =>
#_setUserInput(result.text)
.fail ->
bugsense.notify 'quickform results cannot be fetched' # error here
It caused the coffeescript compiler to throw this error message: Line contains inconsistent indentation (indentation)
Then I rewrite to
fail = -> bugsense.notify 'results cannot be fetched'
new Data({ data_id: #model.get 'id' })
.fetch()
.done (result) =>
#_setUserInput(result.text)
.fail fail
It passes
My first version looks correct. So what it caused the invalid indentation error?
You should have tabs and spaces mixed in your file, because I have tried to compile your code and It seems to be ok (you can check here that your code is right).
If your file uses 2 or 4 spaces to indent, and you are mixing spaces with tabs your compilation is going to fail because your file has unconsistent indentation.
Related
I've recently installed PMD and it's working... however, when I try to suppress a specific warning:
#SuppressWarnings('PMD.EmptyStatementBlocks')
if (a == b) {
// empty statement block
}
This works fine... insofar as it suppresses the warning, but it breaks the Prettier plugin document formatting:
["ERROR" - 9:59:32 AM] Error formatting document.
Error: Unexpected token '#'.. Syntax(error = UnexpectedToken(loc = (11, 5, 67, 68), token = '#'))
What am I doing wrong?
I have a TYPO3 9.5.0LTS and use the bootstrap package theme. It seems to be all working ... I defined the site configuration and then I get nice looking urls ... but quite often I get such error messages:
Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1436717266: Invalid header value for header "Expire"". The value must be a string or an array of strings. | InvalidArgumentException thrown in file /is/www/typo3_src-9.5.0/typo3/sysext/core/Classes/Http/Message.php in line 208. Requested URL: domain/content-examples/media/audio
What causes this and how to prevent this?
Edit: Might be this part in TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getHttpHeadersForTemporaryContent() on line 4244:
/**
* Returns HTTP headers for temporary content.
* These headers prevent search engines from caching temporary content and asks them to revisit this page again.
* Please ensure to also send a 503 HTTP Status code with these headers.
*/
protected function getHttpHeadersForTemporaryContent(): array
{
return [
'Retry-after' => '3600',
'Pragma' => 'no-cache',
'Cache-control' => 'no-cache',
'Expire' => 0,
];
}
... so I change it to 'Expires' => 0
https://forge.typo3.org/issues/86651#change-388813
It seems there's a typo in "Expire" header, should be "Expires".
Try to change it in:
TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getHttpHeadersForTemporaryContent()
while they're fixing this problem
UPD
TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController, line 4244
'Expire' => 0,
change to
'Expires' => '0',
https://forge.typo3.org/issues/86658
And correct header name should be 'Expires' afaik:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires
I think to change the file:
typo3_src-9.5.0/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
on line 4244 from
'Expire' => 0,
to
'Expire' => '0',
helps. The issue is reported https://forge.typo3.org/issues/86658 and will be changed with the next update, I am sure.
Taking a look at the following segment of code you will see two cases where the sencha cmd return an error and one case that it doesn't
var memoryStore = new MemoryStore<Individual>("personnel", [
'name', 'email', 'phone'
], [
new Individual("Batman", "etsigoustaro#thefirm.com", "+306969696969"),
new Individual("Jean Luc", "jeanluc.picard#enterprise.com", "555-111-1111"),
new Individual("Worf", "worf.moghsson#enterprise.com", "+30 696 969 6969"),
new Individual("Deanna", "mr.data#enterprise.com", "+30 6969696969"),
new Individual("Data", "deanna.troi#enterprise.com", "+30-6969696969"),
])
//memoryStore.toExtJS()
Ext.define('extTestTs.store.Personnel', (function(){
//return JSON.stringify(memoryStore.toExtJS()) //fails
//return Ext.Object.merge({},{}) //fails
return {} //succeeds
})());
As you see we have removed everything, even extends is missing but as long as you are typing an object by hand it works. When this object is returned from a function it stops to work!
What does the sencha cmd does behind the scenes? Is it parsing the plain javascript as a text file?..
Because if it was javascript it would run without an issue.
This is the error from sencha cmd console output:
[ERR] C2008: Requirement had no matching files (extTestTs.store.Personnel) -- /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js:8:10
[ERR]
[ERR] BUILD FAILED
[ERR] com.sencha.exceptions.ExBuild: Failed to find any files for /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js::ClassRequire::extTestTs.store.Personnel
[ERR]
[ERR] Total time: 3 seconds
[ERR] The following error occurred while executing this line:
/home/student/bin/Sencha/Cmd/6.1.2.15/plugins/ext/current/plugin.xml:425: The following error occurred while executing this line:
/home/student/Desktop/Typescript/extTestTs/.sencha/app/build-impl.xml:380: The following error occurred while executing this line:
/home/student/Desktop/Typescript/extTestTs/.sencha/app/init-impl.xml:382: com.sencha.exceptions.ExBuild: Failed to find any files for /home/student/Desktop/Typescript/extTestTs/classic/src/view/main/List.js::ClassRequire::extTestTs.store.Personnel
How could we overcome this restriction of explicitly defining the object and rather define it more dynamically?
The goal is to make typescript work with ExtJS but not with the extreme unconventional solutions others propose, like forking typescript itself
Found a workaround
First allow unreachable code in typescript
Here is a screenshot from the IntelliJ settings:
And the code in the questions transforms into that
var memoryStore = new MemoryStore<Individual>("personnel", [
'name', 'email', 'phone'
], [
new Individual("Batman", "etsigoustaro#thefirm.com", "+306969696969"),
new Individual("Jean Luc", "jeanluc.picard#enterprise.com", "555-111-1111"),
new Individual("Worf", "worf.moghsson#enterprise.com", "+30 696 969 6969"),
new Individual("Deanna", "mr.data#enterprise.com", "+30 6969696969"),
new Individual("Data", "deanna.troi#enterprise.com", "+30-6969696969"),
])
//memoryStore.toExtJS()
Ext.define('extTestTs.store.Personnel', function (Personnel) {
return memoryStore.toExtJS()
return {} //do not erase this line
});
Yeah the line return {} might seem totally redundant but (obviously) the sencha cmd is trying to parse the file before it includes it in the requires
Now sencha cmd gives a success and executing sencha app web start the sample app works ok
I want to use restful in my ci 3.03 application:
I found this tutplus tutorial
I downloaded codeigniter-restserver-master.zip file and copied Format.php and REST_Controller.php(#version 3.0.0) files into /application/libraries/REST directory
I created control application/controllers/api/Users.php :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
class Users extends REST_Controller
{
//protected $rest_format = 'json';
function users_get()
{
//$users = $this->user_model->get_all();
$filter_username= $this->get('filter_username');
$filter_user_group= $this->get('filter_user_group');
$filter_active= $this->get('filter_active');
$sort= $this->get('sort');
$sort_direction= $this->get('sort_direction');
//, $filter_user_group, $filter_active, $sort, $sort_direction
$users_list = $this->muser->getUsersList(false, ''/*, $filter_username, $filter_user_group, $filter_active, $sort, $sort_direction, ''*/);
echo '<pre>'.count($users_list).'::$users_lists::'.print_r($users_list,true).'</pre>';
if($users_list)
{
$this->response($users, 200);
}
else
{
$this->response(NULL, 404);
}
}
AND RUNNING URL http://local-ci3.com/api/users I got many errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 734
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 734
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Users::$format
Filename: REST/REST_Controller.php
Line Number: 752
Backtrace:
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 752
Function: _error_handler
File: /mnt/diskD_Work/wwwroot/ci3/application/libraries/REST/REST_Controller.php
Line: 649
Function: response
File: /mnt/diskD_Work/wwwroot/ci3/index.php
Line: 292
Function: require_once
Actually I wanted to get some workable library to help me with REST api creation. I think that is preferable way istead of making from zero.
But is this library not workable or does it needs for some fixing? Sorry, what I missed is if this library only for ci 2?
I made search on this forum and found such hint :
I have the same problem when I load both Format.php and
Rest_Controller.php into a controller. After have a quick glance at
Format.php, it appears to be a standalone format conversion helper.
Try to just load Rest_Controller.php and see if your problem goes
away.
I commented line
//require_once("application/libraries/REST/Format.php");
in my controller, but I still get errors like :
Message: Undefined property: Users::$format.
I tried to review code of this library and see that invalid block when data are converted to json format, line 731-757 :
elseif ($data !== NULL)
{
// If the format method exists, call and return the output in that format
if (method_exists($this->format, 'to_' . $this->response->format))
{
// Set the format header
$this->output->set_content_type($this->_supported_formats[$this->response->format], strtolower($this->config->item('charset')));
$output = $this->format->factory($data)->{'to_' . $this->response->format}();
// An array must be parsed as a string, so as not to cause an array to string error
// Json is the most appropriate form for such a datatype
if ($this->response->format === 'array')
{
$output = $this->format->factory($output)->{'to_json'}();
}
}
else
{
// If an array or object, then parse as a json, so as to be a 'string'
if (is_array($data) || is_object($data))
{
$data = $this->format->factory($data)->{'to_json'}();
}
// Format is not supported, so output the raw data as a string
$output = $data;
}
}
If I tried to commented this block, but get error
Message: Array to string conversion
Looks like data are not converted in this case...
Is is possible to fix these errors?
Or can you, please, to tell me advice some codeigniter 3 REST api workable library with similar interface like library above?
Thanks!
I use that lib, work just fine. My suggestion is follow the more relevant installation instruction on github .
you also wrong place the lib file :
Tutorial say :
require(APPPATH'.libraries/REST_Controller.php');
You try :
require_once("application/libraries/REST/REST_Controller.php");
require_once("application/libraries/REST/Format.php");
No need to include the format because on line 407 the lib will load it. And also good to know on line 404 it will load the configuration (application/config/rest.php) it will be your default configuration, and also you can change it to suit your need.
Please let me know if you still got error using my answer :)
I get the following error:
Uncaught TypeError: Cannot call method 'push' of undefined
In the next code:
class classDemo
names : ['t1', 't2']
methodM1: () ->
# This works:
#names.push 't3'
console.log #names.toString()
#socket = io.connect()
#socket.on 'connect', () ->
# This raise the error:
#names.push 't4'
console.log #names.toString()
Does anyone know how to push into "names" inside the socket.on method? (How to push 't4' correctly?
Thanks
EDIT: The solution proposed by #Sven works for one level of chaining. It seems to fail for two chained calls. Please consider the following example:
methodM1: () ->
_this = #
#socket = io.connect() # connect with no args does auto-discovery
#socket.on 'connect', () ->
# This works:
_this.names.push 'inside connect'
console.log _this.names.toString()
#socket.emit 'getModels', (data) ->
# This does not work:
_this.names.push 'inside emit'
console.log _this.names.toString()
I tried to apply the same solution again inside connect and before emit (see below) but I get no output:
_this2 = _this
#socket.emit 'getModels', (data) ->
_this2.names.push "inside emit"
console.log _this2.names.toString()
Thanks.
your emit is never fired because emit sends data and requieres therefore a datastructure.
Please change your code like this
a) use the fat arrow
b) emit a data structure
methodM1: ->
#socket = io.connect()
#here use the fat arrow it does the '_this = # automatically'
#socket.on 'connect', =>
#names.push 'inside connect'
console.log _this.names.toString()
#socket.emit 'getModels', yo: "got your message"
The fat arrow always binds to the outer instance (see When does the "fat arrow" (=>) bind to "this" instance)
I am not sure (well, I am pretty sure but havent tried it) that you can send a closure over the wire.