Welcome Guest, Not a member yet? Register   Sign In
Controller or its method is not found
#1
Question 

Hello, I have a problem with my CodeIgniter4 and i dont understand.

The Error : 404 - File Not Found

Controller or its method is not found: \App\Controllers\Cconteneur::chercher


But my Method is already into my Controller. 

Controller : 

namespace App\Controllers;

use App\Models\Mconteneurs;

class Cconteneurs extends BaseController
{
    public function index()
    {
        $model = new Mconteneurs();

        $data['result'] = $model->getAllWithPager();
        $data['pager'] = $model->pager;

        $page['contenu'] = view('v_conteneurs', $data);
        return view('Commun/v_template', $page);
    }

    public function chercher()
    {
        $model = new Mconteneurs();
        $texte = $this->request->getGet('recherche');

        if ($texte != NULL)
        {
            $data['result'] = $model->getSearchWithPager($texte);
            $data['pager'] = $model->pager;

            $page['contenu'] = view('v_conteneurs', $data);
            return view('Commun/v_template', $page);
        }
        else
        {
            $data['result'] = "Désolé, votre recherche n'a rien donné.";
        }
    }
}

Method : 

namespace App\Models;

use CodeIgniter\Model;

class Mconteneurs extends Model
{
    protected $table ='conteneur';
    protected $primaryKey = 'Id';
    protected $returnType = 'array';

    public function getAll()
    {
        $requete = $this->select('*')
                        ->orderBy('Id', 'ASC');
        return $requete->findAll();         
    }

    public function getAllWithPager()
    {
        $requete = $this->select('Id, AddrEmplacement');
        return $requete->paginate(8);         
    }

    public function getSearchWithPager($search)
    {
        $requete = $this->select('Id, AddrEmplacement')
                        ->like(['AddrEmplacement' => $search]);
        return $requete->paginate(8);
    }
}

And the view : 

<script src="<?php base_url() ?>js/js_conteneurs.js" defer></script>


<article>
    <div id="contSection1">
        <h1 id="titreConteneur">TOUT LES <span id="colorTitreConteneurs">CONTENEURS</span></h1>

        <hr size="2" color="#00862d" noshade>

        <div id="listeConteneur">
            <form action="<?php echo base_url('Cconteneur/chercher'); ?>" method="get">
                <input type="text" name="recherche" placeholder="Ville ou Adresse désirée" id="carreRecherche">
                <input type="submit" value="Rechercher" id="boutonRecherche">
            </form>
            <div>
                <?php

                if ($result != NULL) {
                    foreach ($result as $row) {
                        echo '
                    <div id="styleConteneurs">
   
                        <p> ' . $row["Id"] . ' - ' . $row["AddrEmplacement"] . ' </p>
                        <a href="#">Plus d\'information</a>
   
                    </div>
                ';
                    }
                } else {
                    echo 'Erreur détecté.';
                }
                ?>
            </div>
            <div id="contSection2">
                <?php echo $pager->links(); ?>
            </div>
        </div>
    </div>
</article>

That happen when i do an research, I dont know why cause as you can see my method "chercher" is created in my controller. Ty for the help Smile
Reply
#2

How do you configure Routes.php?
Do you use auto routing?
Reply
#3

You have a typo. Your class is the plural version, Cconteneurs, while the route is looking for the singular version, \App\Controllers\Cconteneur::chercher.
Reply
#4

Saw that myself, tipical error.

Thanks @kilishan.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(03-23-2023, 09:19 PM)kilishan Wrote: You have a typo. Your class is the plural version, Cconteneurs, while the route is looking for the singular version, \App\Controllers\Cconteneur::chercher.

Ty so much !!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB