Welcome Guest, Not a member yet? Register   Sign In
Dynamic $allowedFields?
#1

(This post was last modified: 12-17-2020, 01:53 AM by blaasvaer.)

Hi,

I've created a dynamic API where the schema for the resource is built on the client based on DB field types (think Content Types in a headless cms). Now, all this dynamic breaks, because I 'have to' hard code the 'allowed_fields' property in the model (I'm actually passing them in from a config in the Controller, but anyway).

Now, are there ANY clever way – apart from passing the fields from the client as an array and somehow inject them into the Controller, and then pass them on to the Model, which is the only way I can see at the moment – to make this dynamic in a (built in/feature) way?

I'm thinking a way to 'override' or 'ignore' the $allowFields all together. As I understand from the docs, all fields NOT defined here will be ignored.
Reply
#2

There is one, but is in the development version. This is yet for release in 4.0.5 or 4.1.

PHP Code:
// use setAllowedFields()
$model model('MyModel');
$model->setAllowedFields($theNewAllowedFieldsArray); 
Reply
#3

Thanks, that's what I'm trying to implement myself. But I need access to the $request in my __construct, as that it where I setup everything based on configurations.

And I don't get the idea behind initController() and therefore I cannot use it. I can't implement something that doesn't make any sense to me.
Reply
#4

(12-17-2020, 09:40 AM)blaasvaer Wrote: Thanks, that's what I'm trying to implement myself. But I need access to the $request in my __construct, as that it where I setup everything based on configurations.

And I don't get the idea behind initController() and therefore I cannot use it. I can't implement something that doesn't make any sense to me.
What needs to be setup in __construct() of a Controller that cannot be setup in initController?
You say you setup "everything", could you give an example?
Reply
#5

It’s a matter of what’s ‘standard’ in PHP ...
Reply
#6

(This post was last modified: 12-17-2020, 01:35 PM by tgix.)

(12-17-2020, 12:54 PM)blaasvaer Wrote: It’s a matter of what’s ‘standard’ in PHP ...
Fair enough, but initController is the standard of the CI4 framework.

I do much of my programming in a JavaScript framework and many of the techniques they use in that framework to initialize objects and run code doesn't rely on me using native JavaScript functions, but instead use factory functions and other design patterns. In JavaScript (and especially while IE11 was around) this removes much of the hassle with browsers that act differently.
Anyhow - wishing you all the best in your efforts.
Reply
#7

PHP Code:
$request = \Config\Services::request(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB