CodeIgniter Forums
How to use is_unique? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: How to use is_unique? (/thread-76171.html)



How to use is_unique? - 5flex - 04-18-2020

I have a controller with code:
PHP Code:
...... other code .....
$props['login'] = 'test';
$props['mail'] = '[email protected]';

$this->validation->run($props'myrules');
...... 
other code ...... 

And now....In my app/Config/Validation.php I write next property:

PHP Code:
public $myrules = [
        
'login' => "is_unique[admins.login,id,{id}]",
        
'mail'  => 'is_unique[admins.mail,id,{id}]',
          



How I can transfer in THIS rule my VARIABLE WITH user ID??!!!

I want to GET the next code (as example):
PHP Code:
public $myrules = [
        
'login' => "is_unique[admins.login,id,314]",
                'mail'  => 'is_unique[admins.mail,id,314]',

    ];

// and next will GET query
// SELECT 1 FROM admins WHERE login = 'test' AND id != 314 


My QUESTION: "HOW TO SEND VARIABLE VALUE IN THE LAST ARGUMENT FROM MY CONTROLLER DINAMICALLY?"


RE: How to use is_unique? - includebeer - 04-18-2020

The placeholder should be replaced automatically by the value in the data array. See https://codeigniter4.github.io/userguide/models/model.html#validation-placeholders


RE: How to use is_unique? - 5flex - 04-18-2020

(04-18-2020, 03:40 PM)includebeer Wrote: The placeholder should be replaced automatically by the value in the data array. See https://codeigniter4.github.io/userguide/models/model.html#validation-placeholders

Have you carefully read my question?

Pay attention to my post! Did I ask somewhere about Models? I asked how to make validation from the controller, and not from Models.


RE: How to use is_unique? - includebeer - 04-19-2020

Hey, calm down. It's not with that kind of attitude that you'll get help here.

Since the Controller and Model both use the Validation library, I assumed they both work the same way. I looked at the code and it seems only the Model take care of the placeholders in the rules, with its fillPlaceholders() function.


RE: How to use is_unique? - 5flex - 04-19-2020

(04-19-2020, 04:47 AM)includebeer Wrote: Hey, calm down. It's not with that kind of attitude that you'll get help here.

Since the Controller and Model both use the Validation library, I assumed they both work the same way. I looked at the code and it seems only the Model take care of the placeholders in the rules, with its fillPlaceholders() function.


I'm from Russia and sorry for my bad English! I used Google Translate service to describe my problem and probably my text was strict.

I'm very sad at this version of Codeigniter. This is not release! It's maximum is BETA! I meet everyday so many bugs on each step in development process! In Views (I'm wrote in github)- bugs, In Models - bugs, In Libraries - bugs (as this) and so on.


RE: How to use is_unique? - jreklund - 04-19-2020

Hi, I'm sad you feel that way about the software. But these are new found bugs that no one discovered in the release candidate face. As with all open source project, finding people to test the software are hard. Our user base for CodeIgniter 4 have increased significantly after the official release, because people actually start using everything.

That's why there are a lot of bugs to take care of at the moment. More people using it, in different ways. Leading to different "bugs" and solutions.

This particular bug have got a Pull request the other day, but haven't been merged in just yet.
https://github.com/codeigniter4/CodeIgniter4/pull/2819