• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation ... callback doesn't get triggered

#21
[eluser]FinalFrag[/eluser]
That is actually a quite good solution.

I was ok with the text the required-error gave, I just hated it that it would show an error message for every field. This pretty much solves my problem without doing something difficult (like the MY_Validation thing) because I'm kinda new with CI.

#22
[eluser]xwero[/eluser]
True but then he can't do his custom validation but FinalFrags problem makes me wonder if the validation library needs to have an option to group error messages into one custom error message. There are a few other scenarios i can think of where it can be useful. This is going on my todo list for my own validate library.
It already has the possibility to add custom error messages Wink

#23
[eluser]wiredesignz[/eluser]
The only way to learn CI is to break it occasionally. Tongue

#24
[eluser]FinalFrag[/eluser]
Yeah, but I'm not up to that level to write my own libraries and such.

About these libraries... I now have a bunch of custom functions that I use in my application. I put them in a file functions.php (and uploaded it in system/application/libraries), it looks like this:

Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Functions {
    function isLoggedIn() {
        if ($this->session->userdata('username')) {
            return true;
        }
        
        return false;
    }
    
    // more functions ...
}
?>

To be able to use these functions I have added the following line to my autoload.php:

Code:
$autoload['libraries'] = array('database', 'session', 'functions');

When I now need a function, I call it like this:

Code:
if (Functions::isLoggedIn()) {
    // code here
}

Is this the right way to do it in CodeIgniter? Or am I doing it wrong?

#25
[eluser]xwero[/eluser]
it can be even simpler for FinalFrags situation if you use the error_string approach
Code:
if($this->validation->error_string != '')
{
   $this->validation->error_string = 'custom message';
}

#26
[eluser]FinalFrag[/eluser]
Yes, but then I'd have 1 error message for ALL errors that may occur. That's not exactly what I want.

Can someone please look at my functions thing and give me some reply on that?

#27
[eluser]wiredesignz[/eluser]
I generally install libraries that contain static methods as helpers ie: functions_helper.php

It's only a personal preference though, Libraries are intantiated when loaded, helpers are not.

Helper classes also have access to the CI super object whereas instantiated libraries do not.

#28
[eluser]xwero[/eluser]
the CI way for loaded libraries is
Code:
$this->functions->isLoggedIn()

#29
[eluser]FinalFrag[/eluser]
Ok, that about solveds all my question I have at the moment. Thanks guys, and a big thank you to the developers of CodeIgniter too, great work on this framework...

#30
[eluser]wiredesignz[/eluser]
Congrats xwero you made 2000+ posts Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.