Welcome Guest, Not a member yet? Register   Sign In
create my own controller
#1

[eluser]welzai[/eluser]
hi guys,i am needs of help. I want to create my own controller, i am making this way


Code:
<?php
class MY_Controller extends Controller{

      function MY_Controle()
      {
        parent::Controller();
        $this->load->model('Cadastro/Menu_mod','menu');
        $this->load->helper('url');
        $this->load->helper('date');
      }


      function Proximo_codigo($field,$table)
      {
        $query = $this->db->query("SELECT IFNULL((MAX($field)+ 1),1) id FROM $table");

        foreach ($query->result() as $row)
        {
          $id = $row->id;
        }
        return  ($id);
      }
}
?>
afterward i saved with name MY_Controle.php in folder "application\libraries " of my application CI, afterward i create other file children of MY_Controller

in my controller childrens
Code:
<?php
class Modelo_ctl extends MY_Controle{

      
      function Modelo_ctl()
      {
        parent::MY_Controle();
        $this->load->model('Cadastro/Modelo_mod','Modelo');
      }

      function index()
      {
        $data['monta_menu'] = $this->menu->Monta_menu();
        $this->load->view('Cadastro/menu',$data);
        $this->load->view('Cadastro/Modelo');
      }

      function Inserir()
      {
        $dados = array();
        $dados['IdModelo'] = $this->Proximo_codigo();
        if (isset($_POST['nome']))
          $dados['nome'] = $_POST['nome'];
        $formato = "y%m%d% - h%:i%";
        $dados['ativo'] = '1';
        $dados['atualizacao'] = date($formato,time());
        $this->Modelo->Inserir($dados);
      }
}
?>

i thought that will run, but don't run

when i wrong. someone can help me please...

i sorry my english... RSRSRSRSRS
#2

[eluser]pmoroom[/eluser]
I believe your controller class name needs to match your file name with the first letter within the class being upper case. I also believe it needs to be under your application/controllers folder unless you modded the config.
#3

[eluser]welzai[/eluser]
i always create my files this way and run. this my pattern
#4

[eluser]welzai[/eluser]
i changed the directory for "application\controllers" and don't run.
#5

[eluser]skunkbad[/eluser]
[quote author="welzai" date="1249542188"]hi guys,i am needs of help. I want to create my own controller, i am making this way


Code:
<?php
class MY_Controller extends Controller{

      function MY_Controle()
      {
        parent::Controller();
        $this->load->model('Cadastro/Menu_mod','menu');
        $this->load->helper('url');
        $this->load->helper('date');
      }


      function Proximo_codigo($field,$table)
      {
        $query = $this->db->query("SELECT IFNULL((MAX($field)+ 1),1) id FROM $table");

        foreach ($query->result() as $row)
        {
          $id = $row->id;
        }
        return  ($id);
      }
}
?>
afterward i saved with name MY_Controle.php in folder "application\libraries " of my application CI, afterward i create other file children of MY_Controller

in my controller childrens
Code:
<?php
class Modelo_ctl extends MY_Controle{

      
      function Modelo_ctl()
      {
        parent::MY_Controle();
        $this->load->model('Cadastro/Modelo_mod','Modelo');
      }

      function index()
      {
        $data['monta_menu'] = $this->menu->Monta_menu();
        $this->load->view('Cadastro/menu',$data);
        $this->load->view('Cadastro/Modelo');
      }

      function Inserir()
      {
        $dados = array();
        $dados['IdModelo'] = $this->Proximo_codigo();
        if (isset($_POST['nome']))
          $dados['nome'] = $_POST['nome'];
        $formato = "y%m%d% - h%:i%";
        $dados['ativo'] = '1';
        $dados['atualizacao'] = date($formato,time());
        $this->Modelo->Inserir($dados);
      }
}
?>

i thought that will run, but don't run

when i wrong. someone can help me please...

i sorry my english... RSRSRSRSRS[/quote]

Your MY_Controle method of your MY_Controller class needs to be named MY_Controller if you intend for it to load as a constructor.

Then, if you want to extend the MY_Controller class, you need to extend MY_Controller, NOT MY_Controle.
#6

[eluser]welzai[/eluser]
yes, it's true, i wrote wrong, but my code is right.
#7

[eluser]welzai[/eluser]
guys, I Still did not solve my problem about create Controller, I already researched
in everywhere
#8

[eluser]skunkbad[/eluser]
[quote author="welzai" date="1249596492"]yes, it's true, i wrote wrong, but my code is right.[/quote]

You can't extend a function that is within a class, you extend the class, and then you add the same function to that class to override the original function.
#9

[eluser]Johan André[/eluser]
I would recommend using somekind of general language when coding (english).
Since the frameworks naming convention is based on english it might help you. I personally think it's easier to troubleshoot code that uses english naming, escpecially when helping other people with their code.
#10

[eluser]welzai[/eluser]
at last, run! the problem was name of class that would be MY_Controller and was MY_Controler, but thank you all




Theme © iAndrew 2016 - Forum software by © MyBB