restler 3 api explorer incorrect param type - restler

first thx for this simple tool!
I got the following problem. In my service class i have a function which looks like this (part):
/**
* get merkmale from device id
*
* one could get merkmale from given serial id by passing var id
* to this function and will get back one to n results ORDER BY ORDNUNG ASC
* in JSON format
*
* #url GET /:id/merkmale
* #param int $id contains the device id
* #throws 400 No value given for id
* #return json
*
*/
function getmerkmale ($id) {....}
The problem is, if i call the api explorer and the phpdocs all is ok but
the #param type (int) is always shown as string value.
And if i try it by typing the required value into field it says wrong value for $id.
I can type in int or string both fails. If i call it in the browser all works.
I use Restler 3 with apiExplorer on Safari/Firefox.
Hope one could help.
Thx
Inge
EDIT:
#Lucarest I tried the actual git clones already without success
Maybe the problem is in index.html?
<?php
use Luracast\Restler\Restler;
require_once 'vendor/restler.php';
require_once 'database/config.php';
require_once 'database/DB.php';
require_once 'controller/Say.php';
require_once 'controller/Authors.php';
require_once 'controller/kunde/kunde.php';
require_once 'controller/device/device.php';
require_once 'controller/messprotokoll/messprotokoll.php';
$r = new Restler();
$r->addAPIClass('Luracast\Restler\Resources'); //this creates resources.json at API Root
$r->addAPIClass('Say');
$r->addAPIClass('Authors');
$r->addAPIClass('kunde');
$r->addAPIClass('device');
$r->addAPIClass('messprotokoll');
//... add more api model if needed
$r->handle();
I have placed all the APIClasses into subfolders. I didnĀ“t get it to work by passing
the url to AddAPIClass as second paramter so i require_once the needed classes.
Could this be the problem?
Thx for your help
Inge

When you are adding namespaced classes using addAPIClass make sure you escape the slashes as shown below
<?php
use Luracast\Restler\Restler;
require_once 'vendor/restler.php';
require_once 'database/config.php';
require_once 'database/DB.php';
require_once 'controller/Say.php';
require_once 'controller/Authors.php';
require_once 'controller/kunde/kunde.php';
require_once 'controller/device/device.php';
require_once 'controller/messprotokoll/messprotokoll.php';
$r = new Restler();
$r->addAPIClass('Luracast\\Restler\\Resources'); //note the double slash for escaping
$r->addAPIClass('Say');
$r->addAPIClass('Authors');
$r->addAPIClass('kunde');
$r->addAPIClass('device');
$r->addAPIClass('messprotokoll');
//... add more api model if needed
$r->handle();
If you strick to PSR-0 you will not need require_once for every class

Related

Too few arguments to function Livewire\LivewireManager::mount(), 0 passed in

Thanks in advance for helpful advice. I am using Laravel Livewire for creating components and Jetstrap for authentication for those routes that require it.
At the moment I only have one route set up for testing authentication, yet after I have logged in to view that route, I get the following error:
Too few arguments to function Livewire\LivewireManager::mount(), 0 passed in /var/www/mvp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 261 and at least 1 expected
This seems to be originating from the LivewireManager class, inside the getInstance() function:
public function getInstance($component, $id)
{
$componentClass = $this->getClass($component);
throw_unless(class_exists($componentClass), new ComponentNotFoundException(
"Component [{$component}] class not found: [{$componentClass}]"
));
return new $componentClass($id);
}
It seems to be expecting a component argument from the Facade class in /vendor/laravel/framework/src/Illuminate/Support/Facades/, but isn't getting the component it needs. I checked the page code, and there is definitely a component there.
The Facade function creating the error:
/**
* Handle dynamic, static calls to the object.
*
* #param string $method
* #param array $args
* #return mixed
*
* #throws \RuntimeException
*/
public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
return $instance->$method(...$args);
}
And the page that's supposed to be loading its component:
#extends('layouts.app')
#section('content')
#livewire('component')
#stop
Is there a simple way to fix the problem? Or am I missing something?
I got same error like what you get when i try to passing parameter and then i'm solving the problem by following the documentation with changing the way to render livewire component from using blade directive #livewire() into <livewire: >

How do I access values from .env in Laravel 5.1 TestCase

In Laravel 5.1 TestCase, the baseUrl is hard-coded. I'd like to set it based on the value I have set in .env.
How do I access the .env variables within the TestCase class?
in Laravel 5.0 TestCase, I can get .env variable with following function.
getenv('APP_VARIABLE');
I think it should work with Laravel 5.1 as well as getenv() is a PHP function.
Start Dotenv to get .env variables in the TestCase stage
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
Dotenv::load(__DIR__.'/../');
$this->baseUrl = env('APP_URL', $this->baseUrl);
return $app;
}
I can confirm that Christopher Raymonds suggestion above, replacing the
Dotenv::load call
with
this $app->loadEnvironmentFrom('.env.testing');
works with Laravel 5.4
See Example:
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* #return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
$app->loadEnvironmentFrom('.env');
$this->baseUrl = env('APP_URL', $this->baseUrl);
return $app;
}
I have this in my .env file:
APP_URL=http://project.dev
I then modified the createApplication function in tests/TestCase.php
/**
* Creates the application.
*
* #return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$this->baseUrl = env('APP_URL', $this->baseUrl);
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
Turned out I needed to add the APP_URL key to my phpunit.xml file.
For whatever reason, I thought some .env file would also be loaded in the process but apparently that's not the case.
I modified the createApplication function in tests/TestCase.php adding this lines after bootstrap ...->bootstrap();
$env = new Dotenv\Dotenv(dirname(__DIR__), '../.env');
$env->load();
In Laravel 5.2 I replaced the Dotenv::load call with this ...
$app->loadEnvironmentFrom('.env.testing');

Tx_Extbase_Domain_Repository_FrontendUserRepository->findAll() not working in typo3 4.5.30?

I am trying to run a simple query off of the Tx_Extbase_Domain_Repository_FrontendUserRepository. I cannot get anything to work except findByUid(), not even findAll().
In my controller I have this code which seems to work:
/**
* #var Tx_Extbase_Domain_Repository_FrontendUserRepository
*/
protected $userRepository;
/**
* Inject the user repository
* #param Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository
* #return void */
public function injectFrontendUserRepository(Tx_Extbase_Domain_Repository_FrontendUserRepository $userRepository) {
$this->userRepository = $userRepository;
}
/**
* action create
*
* #param Tx_BpsCoupons_Domain_Model_Coupon $newCoupon
* #return void
*/
public function createAction(Tx_BpsCoupons_Domain_Model_Coupon $newCoupon) {
...... some code .....
$user = $this->userRepository->findByUid(($GLOBALS['TSFE']->fe_user->user[uid]));
$newCoupon->setCreator($user);
...... some code .....
}
but in another function I want to look up a user not by uid but by a fe_users column called vipnumber (an int column) so I tried
/**
* check to see if there is already a user with this vip number in the database
* #param string $vip
* #return bool
*/
public function isVipValid($vip) {
echo "<br/>" . __FUNCTION__ . __LINE__ . "<br/>";
echo "<br/>".$vip."<br/>";
//$ret = $this->userRepository->findByUid(15); //this works!! but
$query = $this->userRepository->createQuery();
$query->matching($query->equals('vip',$vip) );
$ret = $query->execute(); //no luck
.................
and neither does this
$ret = $this->userRepository->findAll();
How can one work but not the others? In my setup I already put
config.tx_extbase.persistence.classes.Tx_Extbase_Domain_Model_FrontendUser.mapping.recordType >
which seems to be necessary for the fiondByUid to work, is i t preventing the other from working?
I am using typo3 v 4.5.30 with extbase 1.3
Thanks
If $this->userRepository->findByUid(15); works, there is no reason why $this->userRepository->findAll(); should not. However $this->userRepository->findAll(); returns not a single Object but a collection of all objects, so you have to iterate over them.
If you add a column to the fe_users, you have to add it to TCA and to your extbase model (you need a getter and a setter), too! After that you can call findByProperty($property) in your repository. In your case that would be
$user = $this->userRepository->findByVipnumber($vip);
This will return all UserObjects that have $vip set as their Vipnumber. If you just want to check if that $vip is already in use, you can call
$user = $this->userRepository->countByVipnumber($vip);
instead. Which obviously returns the number of Users that have this $vip;
You never use $query = $this->createQuery(); outside your Repository.
To add the property to the fronenduser Model you create your own model Classes/Domain/Model/FronendUser.php:
class Tx_MyExt_Domain_Model_FrontendUser extends Tx_Extbase_Domain_Model_FrontendUser {
/**
* #var string/integer
*/
protected $vipnumber;
}
Add a getter and a setter. Now you create your own FrontendUserRepository and extend the extbase one like you did with the model. You use this repository in your Controller. Now you're almost there: Tell Extbase via typoscript, that your model is using the fe_users table and everything should work:
config.tx_extbase {
persistence{
Tx_MyExt_Domain_Model_FrontendUser{
mapping {
tableName = fe_users
}
}
}
}
To disable storagePids in your repository in general, you can use this code inside your repository:
/**
* sets query settings repository-wide
*
* #return void
*/
public function initializeObject() {
$querySettings = $this->objectManager->create('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings->setRespectStoragePage(FALSE);
$this->setDefaultQuerySettings($querySettings);
}
After this, your Querys will work for all PIDs.
I didn't have the opportunity to work with frontend users yet, so I don't know if the following applies in this case:
In a custom table I stumbled uppon the fact, that extbase repositories automatically have a look at the pids stored in each entry and check it against a set storage pid (possibly also the current pid if not set). Searching for a uid usually means you have a specific dataset in mind so automatic checks for other values could logically be ignored which would support your experiences. I'd try to set the storage pid for your extension to the place the frontend users are stored in ts-setup:
plugin.[replace_with_extkey].persistence.storagePid = [replace_with_pid]

Get the id I am passing YII

Im still new to yii and havent been really familar in everything so what i want to do is get the value of the id (xwrg/ixxdfgx.xxx?r=vintages/view&id=2) say my id here is 2 and echo it
Please I hope someone can help
Also, if you use named parameters in your urlManager rules (main/config.php):
'/vintages/<id:\d+>' => 'Vintages/Index', // i.e. http://example.com/vintages/15
Then you can access them like this:
public function actionIndex( $id )
{
echo $id; // Outputs 15
}

Kohana ORM module not working

I'm learning Kohana at the mo and encountering the following error when trying to extend a model to use ORM.
Declaration of Model_Message::create() should be compatible with that of Kohana_ORM::create()
I've enabled the orm in my bootstrap along with the database. The error highlights the following line on the error dump.
class Model_Message extends ORM {
And here is the model code I'm using and failing with...
<?php defined('SYSPATH') or die('No direct script access');
/**
* Message modal
* Handles CRUD for user messages
*/
class Model_Message extends ORM {
/**
* Adds a new message for a user
*
* #param int user_id
* #param string user's message
* #return self
*/
public function create($user_id, $content)
{
$this->clear();
$this->user_id = $user_id;
$this->content = $content;
$this->date_published = time();
return $this->save();
}
}
I've been going through the api documentation and everything is saying that this way of implementing the orm from the model is the correct way to do so. Any pointers would be great.
You need to rename your method (create_message for example) or make it compatible with ORM (because it has the it's own create method which you try to override).