How can I use where method in Lumen
Route::get('/talent/{id}', 'TalentController#talent')->where('id', '[0-9]+');
Gives me this error:
(1/1) FatalThrowableError
Call to undefined method Laravel\Lumen\Routing\Router::where()
Using php 7 and "laravel/lumen-framework": "5.5.*"
Lumen uses a different router than Laravel does.
For Lumen, the regex constraint is directly in the route parameter defintion. Your code would look something like:
$router->get('/talent/{id:[0-9]+}', 'TalentController#talent');
You can read more about Lumen routing and the constraints in the documentation here.
Related
I'm working in an application HMVC CodeIgniter 4.1, all the routes work fine in navigator:
Navigator adress: http://localhost/myapp/public/index.php/installation/shop-data
My module Routes file contains:
$routes->group("installation", ["namespace" => "\Modules\Installation\Controllers"], function ($routes) {
//Example URL: /installation/shop-data
$routes->get("shop-data", "InstallationController::shop_data");
$routes->get("shop-data-post", "InstallationController::shop_data_post");
});
shop_data_post is the function in which I insert the data to the database from the page Form using this:
echo form_open("installation/shop-data-post");
But I obtain this 404 error:
Controller or its method is not found: \App\Controllers\Installation::shop-data-post
How can I get my function correctly from my page formulary?
Thanks
Ok finally I have solved this..
All that I must did was change my module Installation Routes file so:
This line:
$routes->get("shop-data-post", "InstallationController::shop_data_post");
For this:
$routes->match(["get", "post"], "shop-data-post", "InstallationController::shop_data_post");
The error was on the route request method. It must be POST for process the Form data
If I call this Wordpress blog url in a browser
<root...>wp-json/wp/v2/posts?per_page=5&fields=id,link,title
I get back JSON and the result is restricted to 3 fields
So how can I do this when using the node js wp-api module?
I would like something similar to .fields([]) but there is nothing in the docs, can find nothing in the module code.
TypeError: wpapi.posts(...).perPage(...).fields is not a function
Or something like .filter({})
TypeError: wpapi.posts(...).perPage(...).filter is not a function
But I think this might be connected with another Wordpress plugin that's required.
wpapi.posts()
.perPage(5)
.fields(['id','link','title'])
.search( 'search-term' ) //= (search in title or content)
.filter({
category_name: 'islands',
fields: [ 'id','link','title' ]
})
.get(function (err, data) {
..... etc.
TypeError: wpapi.posts(...).perPage(...).fields is not a function
Can anyone point me in the right direction? Thanks
It appears wp-api node module does not allow this.
So I uninstalled it and am now using axios along with standard text urls.
This worked for me:
wpapi.posts().param('_fields', 'id,title,content').get()
The node-wpapi documentation seems to suggest say that perPage() and functions like it are convenience functions that call param(props, value).
wpapi.posts().param('_fields', ['id','title','content']).get()
also seems to work but the first option gives a resulting request url that looks more like the format the Wordpress REST API Handbook uses
I am trying to know how to add query parameters to routes in Lumen
this is an example of a route I created
$app->get('/product/{apikey}','ProductController#getProduct');
This works when I use
http://api.lumenbased.com/product/10920918
but I would like to use it like this
http://api.lumenbased.com/product/?apikey=10920918
I tried this
$app->get('/product/?apikey={apikey}','ProductController#getProduct');
But this gives me MethodNotAllowedHttpException
I would like to know how to write routes with query parameters in Lumen ?
Just do:
$app->get('/product','ProductController#getProduct');
and use:
$request->get('apikey')
in the ProductController#getProduct function.
(That said, validating an API key is better done via middleware...)
I was following the tutorials on https://apigility.org/documentation/content-validation/basic-usage. But, when I tried to inject the input filter service AddressBook\V1\Rest\Contact\Validator in the ContactResource, I get the following error:
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
/Users/.../src/apigility-tutorials/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:529
Message:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for AddressBook\V1\Rest\Contact\Validator
I am not sure if it's an issue with apigility itself, this is why i'm asking if the example shown in the link above actually works when using dependency injection. Thanks
Got it. According to the zf-content-validation doc, the input filter is registered through Zend\InputFilter\InputFilterPluginManager which means I have to get the InputFilterManager service first then get the Contact input filter service as follows:
$inputFilter =
$serviceLocator->get('InputFilterManager')
->get('AddressBook\V1\Rest\Contact\Validator');
Thanks for looking into it.
I use codeigniter to send email
but i have this error
Fatal error: Call to a member function load() on a non-object in /home/brokarsi/public_html/test/system/libraries/Email.php on line 1922
what is this error?
In my version of CodeIgniter (1.7.2) this corresponds to the following line :
$CI->lang->load('email');
I would guess the problem is that the Language library is not loaded but is required by the Email library. Could you try auto-loading the Language library?
system/application/config/autoload.php
$autoload['libraries'] = array(...., 'language');