Controller in cakephp 3 not running - cakephp

In Cakephp 3 I create a Controller "TestController" when I run the code then it shows internal error has occurred
TestController.php
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* #link http://cakephp.org CakePHP(tm) Project
* #since 0.2.9
* #license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Controller;
use App\Controller\AppController; // HAVE TO USE App\Controller\AppController
// use Cake\Event\Event;
class TestController extends AppController
{
public function index()
{
echo "hii";
// if ($this->Auth->identify()) {
// // $this->redirect('uploads/users/'.$_REQUEST['file'])
// $this->redirect($_REQUEST['file'])
// };
// // else $this->redirect('AdminUsers/login');
// else {
// http_response_code(404);
// }
}
}
But I am not able to get it is shows =
hii
Error
An Internal Error Has Occurred
Error: An Internal Error Has Occurred.
Back

Add an template file in src/Template/Test/index.ctp and add some HTML.
You cannot echo within the controller. CakePHP sends the variables to the View and you can access it there:
// in your controller do this:
class TestController extends AppController
public function index() {
$message = "Hii";
$this->set(compact('message'));
}
}
Your Tempate file src/Template/Test/index.ctp should look like this:
<?php
echo $message;
?>

Related

AntMedia Native Interface issues

I would like to implement this AntMedia iOS and Android native interface for Codename One:
import com.codename1.system.NativeInterface;
import com.codename1.ui.PeerComponent;
/**
* #deprecated Native Interface, deprecated because you normally should use the
* public API in the AntMediaClient class.
*/
public interface AntMediaNative extends NativeInterface {
/**
* Initializes the connection.
*
* #param serverURL is WebSocket url to connect (wss://...)
* #param streamId is the stream id in the server to process
* #param mode true means MODE_PUBLISH, false means MODE_PLAY
* #param tokenId is one time token string
* #return PeerComponent
*/
public PeerComponent createPeer(String serverURL, String streamId, boolean mode, String tokenId);
/**
* Starts the streaming according to the mode.
*/
public void startStream();
/**
* Stops the streaming.
*/
public void stopStream();
/**
* Switches the cameras.
*/
public void switchCamera();
/**
* Toggle microphone.
*
* #return microphone current status.
*/
public boolean toggleMic();
/**
* Stops the video source.
*/
public void stopVideoSource();
/**
* Starts or restarts the video source.
*/
public void startVideoSource();
/**
* Get the error.
*
* #return error or null if not.
*/
public String getError();
/**
* Camera open order.By default front camera is attempted to be opened at
* first, if it is set to false, another camera that is not front will be
* tried to be open.
*
* #param openFrontCamera if it is true, front camera will tried to be
* opened, if it is false, another camera that is not front will be tried to
* be opened
*/
public void setOpenFrontCamera(boolean openFrontCamera);
}
I need help on two specific issues.
The first problem is how to get the PeerComponent in which to view the live streaming. I don't understand what I have to do in this case in the native Android and iOS code. Could you answer me with an example code for iOS and Android that returns a PeerComponent? Below are the links to the SDKs documentation, I hope it is enough to answer this question.
The second problem is that the SDK for iOS is written in Swift: how do I call the Swift code from a native interface that must be written in Objective-C? Could you answer me with a code example here too?
Thank you for your support.
This is the documentation of the two SDKs:
Android SDK documentation:
https://github.com/ant-media/Ant-Media-Server/wiki/WebRTC-Android-SDK-Documentation
iOS SDK documentation:
https://github.com/ant-media/Ant-Media-Server/wiki/WebRTC-iOS-SDK-Documentation
When you use the Generate Native Interface tool in the IDE it generates matching native code. That code generates native OS methods for each operating system e.g. in the case of Android the createPeer method will return a View.
So for this case you would need to create an instance of org.webrtc.SurfaceViewRenderer and store it in the class (for followup calls of init) then return that from the createPeer method.

CakePHP 3.3: on tests, it asks for error templates

I've a plugin with only one controller with only one action:
class AssetsController extends Controller
{
/**
* Renders an asset
* #param string $filename Asset filename
* #param string $type Asset type (`css` or `js`)
* #return Cake\Network\Response|null
*/
public function asset($filename, $type)
{
$this->response->type($type);
$this->response->file(ASSETS . DS . $filename);
return $this->response;
}
}
This only sends an asset file.
Now I'm writing a test for an asset file that does not exist.
public function testAssetNoExistingFile()
{
$this->get('/assets/css/noexistingfile.css');
$this->assertResponseFailure();
}
But it asks for error template:
1) Assets\Test\TestCase\Controller\AssetsControllerTest::testAssetNoExistingFile
Cake\View\Exception\MissingTemplateException: Template file "Error/error500.ctp" is missing.
The plugin does not have template and there is no app with templates. So I would expect that it uses templates from CakePHP core, but this does not happen. Where am I wrong?
There is no Error/error500.ctp template in the core, that's something that the application has to supply.
When testing plugins, you should register a proper test application environment, and provide the necessary templates for it. If you look at how the CakePHP core and plugins do it, they create/register a dummy application in the tests folder where such template files can then be placed.
See also
Setting up CakePHP 3 Plugin testing
https://github.com/cakephp/cakephp/tree/3.3.3/tests
https://github.com/cakephp/debug_kit/tree/3.3.3/tests
https://github.com/cakephp/bake/tree/1.2.8/tests

Class not found in a CakePHP shell script

I'm trying to include some classes in my shell script in CakePHP but they don't seem to load.
For example I have a class located in
/app/Lib/php-ews/EWSType/FindItemType.php
My script looks like this :
App::uses('FindItemType', 'Lib/php-ews/EWSType');
class TestShell extends AppShell {
public function main() {
$this->out($this->readbox());
}
public function readbox() {
$request = new EWSType_FindItemType();
}
}
This gives an error:
"PHP Fatal error: Class 'EWSType_FindItemType' not found in "
Not sure what I'm doing wrong here.
PHP Exchange Web Services should be installed in the Vendor folder and loaded via App::import().
From the CakePHP 2.x docs:
Your vendor files may not follow conventions, have a class that differs from the file name or does not contain classes. You can load those files using App::import().
In your case:
App::import('Vendor', 'FindItemType', array('file' => 'php-ews/EWSType/FindItemType.php'));

Is it safe to override Apache CXF's JAXRSBeanValidationInInterceptor to support request-scoped resources?

By default, CXF 3.0.5's JAXRSBeanValidationInInterceptor and JAXRSBeanValidationOutInterceptor do not support validation of arguments passed to request-scoped resource beans. This exclusion is enforced in org.apache.cxf.jaxrs.validation.ValidationUtils.getResourceInstance(Message). Attempting to use a request-scoped resource results in the following warning being logged:
Service object is not a singleton, use a custom invoker to validate
I've spent some time poking around and come up with the following workaround:
/**
* This is a replacement for CXF's builtin
* {#link JAXRSBeanValidationInInterceptor}. This customization supports
* validation of messages handled by non-singleton JAX-RS resource beans. This
* is needed as many of the beans in this project are request-scoped.
*/
public class BeanValidationInInterceptor extends
JAXRSBeanValidationInInterceptor {
/**
* This is a customization of the code in CXF's builtin
* {#link ValidationUtils#getResourceInstance(Message)}.
*
* #see org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor#getServiceObject(org.apache.cxf.message.Message)
*/
#Override
protected Object getServiceObject(Message message) {
final OperationResourceInfo ori = message.getExchange().get(
OperationResourceInfo.class);
if (ori == null) {
return null;
}
if (!ori.getClassResourceInfo().isRoot()) {
return message.getExchange().get(
"org.apache.cxf.service.object.last");
}
final ResourceProvider resourceProvider = ori.getClassResourceInfo()
.getResourceProvider();
return resourceProvider.getInstance(message);
}
}
It seems to work, but as I don't fully understand the reason this wasn't supported in the first place, I'm wondering if it's safe?
Any CXF devs around who can explain if/how I'm shooting myself in the foot here, and what I might do instead?

Javac error when creating GCM demo app (Google App Engine Java/Windows 7)

I'm trying to create a GCM Demo Application for Android on Windows 7 following the "official" tutorial (http://developer.android.com/google/gcm/demo.html).
In particular, I am trying to create a server using Java App Engine as described in said tutorial:
To set up the server using a standard App Engine for Java:
From the SDK Manager, install Extras > Google Cloud Messaging for Android Library. This creates a gcm directory under
YOUR_SDK_ROOT/extras/google/ containing these subdirectories:
gcm-client, gcm-server, samples/gcm-demo-client,
samples/gcm-demo-server, and samples/gcm-demo-appengine.
In a text editor, edit samples/gcm-demo-appengine/src/com/google/android/gcm/demo/server/ApiKeyInitializer.java
and replace the existing text with the API key obtained above.
Note: The API key value set in that class will be used just once to create a persistent entity on App Engine. If you deploy the
application, you can use App Engine's Datastore Viewer to change it
later.
In a shell window, go to the samples/gcm-demo-appengine directory.
Start the development App Engine server by ant runserver, using the -Dsdk.dir to indicate the location of the App Engine SDK and -Dserver.host to set your server's hostname or IP address:
$ ant -Dsdk.dir=/opt/google/appengine-java-sdk runserver -Dserver.host=192.168.1.10
Buildfile: gcm-demo-appengine/build.xml
I have followed these steps, and I get the following error:
C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine>ant -Dsdk.dir C:/Users/p/appengine-java-sdk-1.8.0 runserver -Dserver.host=192.168.44.1 Buildfile: gcm-demo-appengine/build.xml
Buildfile: C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\build.xml
init:
copyjars:
compile:
[javac] Compiling 8 source files to C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\WebContent\WEB-INF\classes
[javac] C:\Users\p\AppData\Local\Android\android-sdk\extras\google\gcm\samples\gcm-demo-appengine\src\com\google\android\gcm\demo\serer\ApiKeyInitializer.java:1: reached end of file while parsing
[javac] AIzbSyBQdFestseFygh7Q22dxEfdsyc_k->
[javac] ^
[javac] 1 error
BUILD FAILED
"reached end of file while parsing" - as I understand it, this error is normally caused by missing brackets - however, all I've done is edit the ApiKeyInitializer.java file in Notepad to enter the API key; I have not touched any code! I have tried to find a solution online, but to no avail.
Does anyone know what might be causing this issue and how I could fix it? Many thanks in advance!
I checked the ApiKeyInitializer.java file (I had it locally on my computer).
It looks like a valid java class :
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.gcm.demo.server;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import java.util.logging.Logger;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/**
* Context initializer that loads the API key from the App Engine datastore.
*/
public class ApiKeyInitializer implements ServletContextListener {
static final String ATTRIBUTE_ACCESS_KEY = "apiKey";
private static final String ENTITY_KIND = "Settings";
private static final String ENTITY_KEY = "MyKey";
private static final String ACCESS_KEY_FIELD = "ApiKey";
private final Logger logger = Logger.getLogger(getClass().getName());
public void contextInitialized(ServletContextEvent event) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
Entity entity;
try {
entity = datastore.get(key);
} catch (EntityNotFoundException e) {
entity = new Entity(key);
// NOTE: it's not possible to change entities in the local server, so
// it will be necessary to hardcode the API key below if you are running
// it locally.
entity.setProperty(ACCESS_KEY_FIELD,
"replace_this_text_by_your_Simple_API_Access_key");
datastore.put(entity);
logger.severe("Created fake key. Please go to App Engine admin "
+ "console, change its value to your API Key (the entity "
+ "type is '" + ENTITY_KIND + "' and its field to be changed is '"
+ ACCESS_KEY_FIELD + "'), then restart the server!");
}
String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
}
public void contextDestroyed(ServletContextEvent event) {
}
}
Perhaps you somehow deleted the contents of that file.

Resources