"This webpage has a redirect loop" |
hi,
I have this problem "This webpage has a redirect loop" at chrome. I have a table named USUARIOS, another ENDERECOS ( this table has 3 addresses per user ) and another one FAVORITA that store the favorite address from user. Let´s go This is the controller that list all addresses of the user: controller: public function escolher_endereco(){ esta_logado(); set_tema('footerinc', load_js(array('jquery-1.10.2.min','jquery.dataTables','dataTables.foundation','table')),FALSE); set_tema('titulo','Escolha de endereço'); set_tema('conteudo', load_modulo('usuarios','escolher_endereco')); set_tema('template','pizza_view'); load_template(); } This is the view loaded to show addresses: view: case 'escolher_endereco': $iduser = $this->session->userdata('user_id'); ?> <div class="large-12 columns"> <?php echo breadcrumb(); get_msg('msgok'); get_msg('msgerro'); ?> <table class="large-12 columns" id="data-table"> <thead> <tr> <th>Nome do Endereço</th> <th>Rua</th> <th>Cidade</th> <th>Favorito</th> </tr> </thead> <tbody> <?php $query_fav=$this->usuarios->get_byid('id_user', $iduser, 'favorita')->row(); // pega endereco favorito $query_end=$this->usuarios->get_byid('id_usuario', $iduser, 'endereco', 3)->result(); // pega todos enderecos foreach ($query_end as $linha): echo '<tr>'; printf('<td>%s</td>',$linha->nome_endereco); printf('<td>%s</td>',$linha->rua); printf('<td>%s</td>',$linha->cidade); printf('<td>%s</td>',($linha->id_endereco==$query_fav->id_endereco)?'Sim':anchor("usuarios/loucura2/$linha->id_endereco", 'Não')); echo '</tr>'; endforeach; ?> </tbody> </table> </div> <?php break; This is another controller to show the new favorite address choose. controller: public function loucura2(){ esta_logado(); $endfavorito = $this->uri->segment(3); $query_fav=$this->usuarios->get_byid('id_user', $this->session->userdata('user_id'), 'favorita')->row(); // pega endereco favorito $dados= array('id_endereco' => $endfavorito); set_tema('titulo','Favoritos'); set_tema('conteudo', load_modulo('usuarios','favorito3')); set_tema('template','pizza_view'); load_template(); } view: case 'favorito3': $iduser = $this->session->userdata('user_id'); $novoendfavorito = $this->uri->segment(3); $query_fav=$this->usuarios->get_byid('id_user', $iduser, 'favorita')->row(); // pega endereco favorito $query_end=$this->usuarios->get_byid('id_endereco', $novoendfavorito, 'endereco')->row(); // pega endereco favorito ?> <div class="large-12 columns"> <?php echo breadcrumb(); get_msg('msgok'); get_msg('msgerro'); ?> <table class="large-12 columns" id="data-table"> <thead> <tr> <th>Nome do Endereço</th> <th>Rua</th> <th>Cidade</th> <th>Favorito</th> <th>Favorita</th> </tr> </thead> <tbody> <?php echo '<tr>'; printf('<td>%s</td>',$query_end->nome_endereco); printf('<td>%s</td>',$query_end->rua); printf('<td>%s</td>',$query_end->cidade); printf('<td>%s</td>',$query_end->id_endereco); printf('<td>%s</td>',$query_fav->id_favorita); echo '</tr>'; ?> </tbody> </table> </div> <?php echo anchor("usuarios/loucura3/$query_end->id_endereco",'Salvar Favorito',array('class'=>'button radius espaco')); break; Here is my problem: this controller calls model to update database, but chrome starts a loop and abort execution with the message "This webpage has a redirect loop". controller: public function loucura3(){ $endfavorito = $this->uri->segment(3); $query_fav=$this->usuarios->get_byid('id_user', $this->session->userdata('user_id'), 'favorita')->row(); // pega endereco favorito $dados= array('id_endereco' => $endfavorito); $this->usuarios->do_update( $dados, 'favorita', array('id_favorita' => $query_fav->id_favorita)); redirect(base_url()); } model: public function do_update($dados=NULL, $mytable, $condicao=NULL, $redir=TRUE){ if($dados !=NULL && is_array($condicao) ): $this->db->update($mytable, $dados, $condicao); if($this->db->affected_rows()>0): set_msg('msgok','Alteração efetuada com sucesso','sucesso'); else: set_msg('msgerro','Erro ao atualizar dados','erro'); endif; This is my last try....I know this is a lot of controllers/views. The problem is on update. I don´t know why? If anyone can help me, thank you so much! Guapo
Guapo
Learning PHP Learning CodeIgniter
Can you wrap you posting cod into a php code block please so its a bit hard to read ^^.
I´m sorry....
This is the controller PHP Code: class Usuarios extends CI_Controller { This is the view PHP Code: switch ($tela): This is the model PHP Code: public function do_update($dados=NULL, $mytable='usuarios', $condicao=NULL, $redir=TRUE){ Thanks
Guapo
Learning PHP Learning CodeIgniter
Your problem should be the double redirect "redirect(base_url());" in your controller and in your model. Remove the one in your model and give back a return value if you want do the redirect.
I think that the problem is in the model...
Code: if ($redir) This code is terrible wrong specially at your case $redir is TRUE by default... NEVER put redirects in your MODEL !!! There is the Logic not the Control !!! Best VPS Hosting : Digital Ocean
(11-23-2014, 02:38 PM)sv3tli0 Wrote: I think that the problem is in the model... Guys, you are all right!!!!!!!!!!! Problem solved! I´m using this model from a course of CodeIgniter....this is not my style, and I´m agree with you 100%. I prefer things explicits. Now, I already cut this "redirect" from the model, and from now on I´ll not use inside procedure!!!! Thank you very much
Guapo
Learning PHP Learning CodeIgniter |
Welcome Guest, Not a member yet? Register Sign In |