Welcome Guest, Not a member yet? Register   Sign In
Using uri_to_assoc more than once - cant use default pars for second one
#1

[eluser]Jelenik[/eluser]
Dear community,

I am developing application where I have id of item in each url (there is no index page, visitor has to have correct link to detail for location info). So I implemented control check in my init() function, which I am calling in each controller.

So I have library Project.php and there init() function:

Code:
function init($uri_segment)
{
          
            
          
            $data['uri_array'] = $this->_CI->uri->uri_to_assoc($uri_segment, array( 'id' ));
            
            /*
             * HERE IS CHECKING FUNCTION - it just calls show_404() function
             * in case I wont fetch any proper result from database otherwise
             * it will continue normally
             */
            
            return $data;
}

Then I have controller Book.php and there function:
Code:
function index()
{
            $data = $this->project->init(2);
            
            $default_pars = array('id', 'day_id');
            
            $data['uri_array'] = $this->uri->uri_to_assoc(2, $default_pars);
            
            var_dump($data['uri_array']);
            
}

If I visit url where day_id segment is not present, I would expect that key 'day_id' will be still present in $data['uri_array'] - but it isnt.. Any idea why it ignored my second $default_pars? Isnt that bug? I would expect that when calling uri_to_assoc second time that it will overwrite previous settings (default_pars).
#2

[eluser]TheFuzzy0ne[/eluser]
It may be a bug. I don't suppose you have a 2 as the third segment in your URL?

Looking in ./system/core/URI.php I can see the following:
Code:
if (isset($this->keyval[$n]))
{
    return $this->keyval[$n];
}

I suspect this may well be returning before it gets to processing your defaults.
#3

[eluser]Jelenik[/eluser]
It seems you are right. However I have altered my code to use just only one uri_to_assoc function - in init() function = I have inserted there all used segment key values across the application. So I dont need to call uri_to_assoc again in Book.php controller. Its simple application, so its not big deal, but someone could need to use uri_to_assoc more than once and cant use my approach...




Theme © iAndrew 2016 - Forum software by © MyBB