Welcome Guest, Not a member yet? Register   Sign In
Call to undefined function - still need help
#1
Sad 
(This post was last modified: 05-14-2024, 09:00 PM by nanohe.)

Hi there,

Good day.
My Code worked on CI V4.4.3.
On my MacOS env it works quite well. 
Mamp Pro with PHP V8.2.0
When I deployed to my local CentOS V7 with PHP V8.2.16. But my app doesn't work on CentOS now.
Error. Call to undefined function display_error()
I already googled some articles and solutions, but these information don't work on my situation.

My code as below,
view page:
the last line is <small class="text-danger"><?= isset($validation) ? display_error($validation, 'email') : '' ?></small>, the erro function trigged from there.
Code:
<form action="<?= base_url('auth/check') ?>" method="post" autocomplete="off">
                                    <?php $validation = \Config\Services::validation(); ?>
                                    <?= csrf_field(); ?>
                                    <?php if( !empty( session()->getFlashdata('fail') ) ) : ?>
                                        <div class="alert alert-danger"><?= session()->getFlashdata('fail'); ?></div>
                                    <?php endif ?>

                                    <!-- Form Group (email address)-->
                                    <div class="mb-3">
                                        <label class="small mb-1" for="inputEmailAddress">Email</label>
                                        <input type="text" name="email" class="form-control" placeholder="Enter your email" value="<?= set_value('email') ?>">
                                        <small class="text-danger"><?= isset($validation) ? display_error($validation, 'email') : '' ?></small>
                                    </div>
......
......

And my controller as this,
Code:
class AuthController extends BaseController
{
    protected $helpers = ['url', 'form'];     // this is the original style. it work on MacOS.

    public function login()
    {
//        helper('form');  // I tried to fix my err and inserted here again. it doesn't work on my CentOS.

        return view('auth/auth-login');
    }

I also tested add the help in BaseController as below since I found one post suggested as this way.

Code:
    protected $request;

    /**
    * An array of helpers to be loaded automatically upon
    * class instantiation. These helpers will be available
    * to all other controllers that extend BaseController.
    *
    * @var array
    */
    protected $helpers = ['form'];

All of these methods don't work.

Could anyone give me other suggestion?

thank you so much.

Best Regards.
Nano HE.
Reply
#2

What is the function display_error()?
There is no such function in PHP or CodeIgniter.
Reply
#3

(05-14-2024, 09:16 PM)kenjis Wrote: What is the function display_error()?
There is no such function in PHP or CodeIgniter.


It comes from ci/app/Helpers/Form_helper.php

Code:
<?php
function display_error($validation, $field){
    if( $validation->hasError($field) ){
        return $validation->getError($field);
    }else{
        return false;
    }
}


?>
Reply
#4

(This post was last modified: 05-14-2024, 09:39 PM by kenjis.)

The Form helper file must be "form_helper.php".
See https://codeigniter.com/user_guide/gener...g-a-helper
Reply
#5

(05-14-2024, 09:36 PM)kenjis Wrote: The Form helper file must be "form_helper.php".
See https://codeigniter.com/user_guide/gener...g-a-helper

Thanks a lot. it works now.
I need read the guide more detail and carefully.

Best Regards
NanoHE.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB