Welcome Guest, Not a member yet? Register   Sign In
Problem with Routers
#1

[eluser]Ivan Augusto[/eluser]
Hi Guys, i need some assistance.

My Controllers:

Code:
<?
class Projetos extends Controller {
    function Projetos()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
    }
    function index()
    {
        $data['titulo'] = "Projetos";
        $data['projetos'] = $this->db->get('projetos');
        $this->load->view('projetos/projetos_view',$data);
    }
}

class Planejamento extends Controller {
    function Planejamento()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
    }
    function index($projeto_id)
    {
        $data['titulo'] = "Planejamentos";
        $data['projeto_id'] = $projeto_id;
        $this->load->view('projetos/planejamento_view',$data);
    }
}
?>

and my Routers:

Code:
$route['projetos'] = "projetos/projetos";
$route['projetos/:num/planejamento'] = "projetos/planejamento/index";

but i have this problem:

Quote:A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Planejamento::index()
Filename: projetos/planejamento.php
Line Number: 9

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: projeto_id
Filename: projetos/planejamento.php
Line Number: 12

Help-me xD~
#2

[eluser]TheFuzzy0ne[/eluser]
Assuming your index method looks something like this:

Code:
function index($arg)
{
    # ...
}

You can set the default value for if an argument is not supplied, so:

Code:
function index($arg=FALSE)
{
    # ...
}

This should stop that error, but you'll need to handle it in your code of course.
#3

[eluser]Ivan Augusto[/eluser]
Thks man... its works =D~

I fixed the routers:

$route['projetos/(:num)/planejamento'] = 'projetos/planejamento/index/$1';

and the parameter has pass XD




Theme © iAndrew 2016 - Forum software by © MyBB