Welcome Guest, Not a member yet? Register   Sign In
URI Segments and links
#1
Sad 

Hi,
I have a problem in redirecting my links after using links with 3 parameters. That is, controller , action and parameter . Ok using a link like this <a href="House/register/1">Edit the house</a>
I walk normally on the page and the right value ( 1). But my mistake is when I click a button on this page to return to the management page "House/index". This button there is this link <a href="House">Come back to the management Houses</a> , which would trigger a House controller and the index action. Ex.: www.web.com/House/index . But my URL is www.web.com/House/register/House, ie the link is becoming a parameter and not a redirect to the controller.


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');
        
        
$dataOfAllHouses$this->houses->returnAllHouses();
        
        
$rows = array();
        foreach(
$dataOfAllHousesas $arrayOfValues){
            
$rows[] = $arrayOfValues;
        }
        
$dataToView= array(
            
'bloco_lista_residencia' => $rows
            
);

        
$this->pushToScreen($dataToView);
    }


    public function 
register(){
        if(
$this->uri->segment(30)){
            
$this->setTitle('House Edit');
            
$idHouse$this->uri->segment(3,0);
            
$dataToView$this->houses->returnDataHouseOfId($idHouse);
        }
        
$this->pushToScreen($dataToView);
    }


Reply
#2

if you want to create links you can create them relative to your domain with echo anchor('whatevercontroller/whatevermodel/params','The link name');
Reply
#3

(07-03-2015, 01:07 AM)Avenirer Wrote: if you want to create links you can create them relative to your domain with echo anchor('whatevercontroller/whatevermodel/params','The link name');

This is not what i want. My problem is not with links. Is the third segment only. If i doesn't pass the third segment in whatever links the links works fine like <a href='whatevercontroller/whateveraction' ></a>

But if i clicked in the edit with the href='whatevercontroller/whateveraction/whateverparam' the uri is www.bla.com/whatevercontroller/whateveraction/whateverparam but if in this screen i clicked in a button to return like this href='whatevercontroller/whateveraction ' the url change only the param putting the controller called like param, like this www.bla.com/whatevercontroller/whateveraction/whatevercontroller

I don't know why when i pass the third param the url bug the link. Just the url doesnt refresh, only set a param with the value of controller of the link clicked
Reply
#4

Start your links with a /. Otherwise they will just append to the current url since they are "relative" urls.

href='/whatevercontroller/whateveraction/whateverparam'
href='/whatevercontroller/whateveraction'
etc
Reply




Theme © iAndrew 2016 - Forum software by © MyBB