Welcome Guest, Not a member yet? Register   Sign In
My URI are redirect wrong
#1
Sad 

Hi everyone! Well i don't speak english so much, so sorry about anything what i write wrong.

Well, I have a problem when i need to get the segment 3 or anything other 4,5,6.

This is my code which the action is register and when it's called, the action get the 3 param of the uri where is set in a link button <a href="House/register/{idhouse_via_template_engine}">Edit the House</a> which is the id of a house for example.

Well, until then everything is okay . But when I click a link where I am coming back to the parent controller , for example , standing on the registration page with the third segment , all working ok and I click on a button to return to the management page : <a href = " House / index " > Back to the management </a> .
My URL , rather than "House/index" is "House/register/House". I don't know what the url doesnt "reset", and symple redirect to the House/index

PHP Code:
<?php

if (!defined('BASEPATH'))
 
   exit('No direct script access allowed');

include_once(
APPPATH 'controllers/IdwellerController.php');

class 
House extends IdwellerController{

 
   public function __construct() {
 
       parent::__construct();
 
       $this->load->helper('url');
 
       $this->load->model('houses');
 
   }

public function 
index() {
 
       $this->setTitle('House management');
 
       
        $allHouses
$this->houses->returnAllHouses();
 
       
        $rows 
= array();
 
       foreach($allHouses as $arrayValues){
 
           $rows[] = $arrayValues;
 
       }
 
       $dataToView= array(
 
           'bloco_lista_residencia' => $rows
            
);

 
       $this->pushToScreen($dataToView);
 
   }

 
   public function register(){
 
       if($this->uri->segment(30)){
 
           $this->setTitle('House editing');
 
           $idHouse$this->uri->segment(3,0);
 
           $dadosParaView $this->houses->returnHouseForId($idHouse);
 
       }else{
 
           $this->setTitle('House register');
 
           $dataToView= array(
 
               'idHouse' => '',
 
               'number' => '',
 
               'local' => ''
 
               );
 
       }
 
       $this->pushToScreen($dataToView);
 
   }

Reply
#2

(07-02-2015, 02:02 PM)ramon183 Wrote: But when I click a link where I am coming back to the parent controller , for example , standing on the registration page with the third segment , all working ok and I click on a button to return to the management page : <a href = " House / index " > Back to the management </a> .
My URL , rather than "House/index" is "House/register/House". I don't know what the url doesnt "reset", and symple redirect to the House/index

I removed everything else in my quote from your original post, because I believe the rest is mostly irrelevant. The answer is that your link is relative (href="House/index"), so you're linking to House/register/House/index. You need to use a full URL, and the best way to do that is usually to use the site_url() function:

PHP Code:
<a href="<?php echo site_url('house/index'); ?>">Back to the management</a
Reply
#3

Or just be sure to put a slash at the beginning of your href, so it resolves to site ROOT instead of relative to whatever the current url is:
<a href="/house'); ?>">Back to the management</a>
Will send you to http://yourhost.com/house

Note you don't have to specify the index method, as that is default if no method is present in the request.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB