Note that there are some explanatory texts on larger screens.

plurals
  1. POkohana 3 routing fails under certain circumstances
    primarykey
    data
    text
    <p>I am having a very annoying problem with Kohana 3 routes and/or something else that is causing my routes to fail.</p> <p>The route in question is defined as:</p> <pre><code>Route::set('module', '(&lt;lang&gt;/)&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;))', array('lang' =&gt; $lang_options, 'controller' =&gt; '(docrepo|calendar|maps|forum)')) -&gt;defaults(array( 'controller' =&gt; 'docrepo', 'lang' =&gt; DEFAULT_LANG, 'action' =&gt; 'index', )); </code></pre> <ul> <li>this route seems to be working fine for almost all cases</li> <li>the specific case that is causing me problems is: /calendar/save</li> <li>accessing the /calendar/save route directly from a tab in Safari or IE <strong>always works</strong> (e.g. <a href="https://my.site.com/calendar/save" rel="nofollow">https://my.site.com/calendar/save</a>)</li> <li>accessing the /calendar/save route directly from a tab in Firefox <strong>sometimes works</strong> (e.g. <a href="https://my.site.com/calendar/save" rel="nofollow">https://my.site.com/calendar/save</a>)</li> <li>accessing the /calendar/save route from AJAX in any browser <strong>always fails</strong> and the page ends up getting caught by my catch-all route and sent to a 404 page, the catch-all route is shown below</li> <li>accessing another action for the same controller and route always works (even via AJAX) (e.g. <a href="https://my.site.com/calendar/edit" rel="nofollow">https://my.site.com/calendar/edit</a> works fine directly or via AJAX in all browsers)</li> </ul> <p>The catch-all route is:</p> <pre><code>Route::set('catch_all', '&lt;path&gt;', array('path' =&gt; '(|.+)')) -&gt;defaults(array( 'controller' =&gt; 'base', 'action' =&gt; '404', )); </code></pre> <p>There are no errors in my apache logs since everything is working as per apache and php. </p> <p>There are no errors in my Kohana logs since everything is working according to Kohana.</p> <p>I added some debug code to my 404 page and here is the output from the ajax call to calendar/save:</p> <pre><code>The requested URI was not found: calender/save The requested URL was not found: https://my.website.com/calender/save Here is the request data: object Request(19) { protected _requested_with =&gt; NULL protected _method =&gt; string(4) "POST" protected _protocol =&gt; string(5) "https" protected _referrer =&gt; NULL protected _route =&gt; object Route(5) { protected _callback =&gt; NULL protected _uri =&gt; string(6) "&lt;path&gt;" protected _regex =&gt; array(1) ( "path" =&gt; string(5) "(|.+)" ) protected _defaults =&gt; array(2) ( "controller" =&gt; string(4) "base" "action" =&gt; string(3) "404" ) protected _route_regex =&gt; string(21) "#^(?P&lt;path&gt;(|.+))$#uD" } protected _response =&gt; object Response(5) { protected _status =&gt; integer 200 protected _header =&gt; object Http_Header(0) { } protected _body =&gt; string(0) "" protected _cookies =&gt; array(0) protected _protocol =&gt; string(5) "https" } protected _header =&gt; object Http_Header(0) { } protected _body =&gt; string(878) "day_number=8&amp;c_record[calendar_event][0][id]=&amp;c_record[calendar_event][0][project_id]=1&amp;c_record[calendar_event][0][start_date_time][date]=2011-03-08&amp;c_record[calendar_event][0][start_date_time][hour]=8&amp;c_record[calendar_event][0][start_date_time][min]=00&amp;c_record[calendar_event][0][start_date_time][sec]=00&amp;c_record[calendar_event][0][start_date_time][modulation]=am&amp;c_record[calendar_event][0][start_date_time][modulation]=pm&amp;c_record[calendar_event][0][end_date_time][date]=2011-03-08&amp;c_record[calendar_event][0][end_date_time][hour]=5&amp;c_record[calendar_event][0][end_date_time][min]=00&amp;c_record[calendar_event][0][end_date_time][sec]=00&amp;c_record[calendar_event][0][end_date_time][modulation]=am&amp;c_record[calendar_event][0][end_date_time][modulation]=pm&amp;c_record[calendar_event][0][title]=adsf&amp;c_record[calendar_event][0][description]=asdf&amp;c_record[calendar_event][0][link]=" protected _directory =&gt; string(0) "" protected _controller =&gt; string(4) "base" protected _action =&gt; string(3) "404" protected _uri =&gt; string(13) "calender/save" protected _external =&gt; bool FALSE protected _params =&gt; array(1) ( "path" =&gt; string(13) "calender/save" ) protected _get =&gt; array(1) ( 1299176419 =&gt; string(0) "" ) protected _post =&gt; array(2) ( "day_number" =&gt; string(1) "8" "c_record" =&gt; array(1) ( "calendar_event" =&gt; array(1) ( 0 =&gt; array(7) ( "id" =&gt; string(0) "" "project_id" =&gt; string(1) "1" "start_date_time" =&gt; array(5) ( ... ) "end_date_time" =&gt; array(5) ( ... ) "title" =&gt; string(4) "adsf" "description" =&gt; string(4) "asdf" "link" =&gt; string(0) "" ) ) ) ) protected _cookies =&gt; array(0) protected _client =&gt; object Request_Client_Internal(5) { protected _previous_environment =&gt; NULL protected _cache =&gt; NULL protected _allow_private_cache =&gt; bool FALSE protected _request_time =&gt; NULL protected _response_time =&gt; integer 1299177212 } public status =&gt; integer 404 } Here is a test to see if this uri should match a route: bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE array(5) ( "path" =&gt; string(13) "calender/save" "controller" =&gt; string(4) "base" "action" =&gt; string(3) "404" "uri" =&gt; string(13) "calender/save" "route" =&gt; object Route(5) { protected _callback =&gt; NULL protected _uri =&gt; string(6) "&lt;path&gt;" protected _regex =&gt; array(1) ( "path" =&gt; string(5) "(|.+)" ) protected _defaults =&gt; array(2) ( "controller" =&gt; string(4) "base" "action" =&gt; string(3) "404" ) protected _route_regex =&gt; string(21) "#^(?P&lt;path&gt;(|.+))$#uD" } ) </code></pre> <p>Here is the same debug code running on a page that is working, as you can see the correct route is showing up as matched:</p> <pre><code>The requested URI wasfound: calendar/index The requested URL wasfound: https://my.website.com/calendar/index Here is the request data: object Request(18) { protected _requested_with =&gt; NULL protected _method =&gt; string(3) "GET" protected _protocol =&gt; string(5) "https" protected _referrer =&gt; string(40) "https://my.website.com/calendar/index" protected _route =&gt; object Route(5) { protected _callback =&gt; NULL protected _uri =&gt; string(39) "(&lt;lang&gt;/)&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;))" protected _regex =&gt; array(2) ( "lang" =&gt; string(7) "(en-ca)" "controller" =&gt; string(29) "(docrepo|calendar|maps|forum)" ) protected _defaults =&gt; array(3) ( "controller" =&gt; string(7) "docrepo" "lang" =&gt; NULL "action" =&gt; string(5) "index" ) protected _route_regex =&gt; string(130) "#^(?:(?P&lt;lang&gt;(en-ca))/)?(?P&lt;controller&gt;(docrepo|calendar|maps|forum))(?:/(?P&lt;action&gt;[^/.,;?\n]++)(?:/(?P&lt;id&gt;[^/.,;?\n]++))?)?$#uD" } protected _response =&gt; object Response(5) { protected _status =&gt; integer 200 protected _header =&gt; object Http_Header(0) { } protected _body =&gt; string(0) "" protected _cookies =&gt; array(0) protected _protocol =&gt; string(5) "https" } protected _header =&gt; object Http_Header(0) { } protected _body =&gt; NULL protected _directory =&gt; string(0) "" protected _controller =&gt; string(8) "calendar" protected _action =&gt; string(5) "index" protected _uri =&gt; string(14) "calendar/index" protected _external =&gt; bool FALSE protected _params =&gt; array(1) ( "lang" =&gt; NULL ) protected _get =&gt; array(1) ( "reset_date" =&gt; string(1) "1" ) protected _post =&gt; array(0) protected _cookies =&gt; array(0) protected _client =&gt; object Request_Client_Internal(5) { protected _previous_environment =&gt; NULL protected _cache =&gt; NULL protected _allow_private_cache =&gt; bool FALSE protected _request_time =&gt; NULL protected _response_time =&gt; integer 1299178100 } } Here is a test to see if this uri should match a route: bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE bool FALSE array(5) ( "lang" =&gt; NULL "controller" =&gt; string(8) "calendar" "action" =&gt; string(5) "index" "uri" =&gt; string(14) "calendar/index" "route" =&gt; object Route(5) { protected _callback =&gt; NULL protected _uri =&gt; string(39) "(&lt;lang&gt;/)&lt;controller&gt;(/&lt;action&gt;(/&lt;id&gt;))" protected _regex =&gt; array(2) ( "lang" =&gt; string(7) "(en-ca)" "controller" =&gt; string(29) "(docrepo|calendar|maps|forum)" ) protected _defaults =&gt; array(3) ( "controller" =&gt; string(7) "docrepo" "lang" =&gt; NULL "action" =&gt; string(5) "index" ) protected _route_regex =&gt; string(130) "#^(?:(?P&lt;lang&gt;(en-ca))/)?(?P&lt;controller&gt;(docrepo|calendar|maps|forum))(?:/(?P&lt;action&gt;[^/.,;?\n]++)(?:/(?P&lt;id&gt;[^/.,;?\n]++))?)?$#uD" } ) bool FALSE bool FALSE bool FALSE array(5) ( "path" =&gt; string(14) "calendar/index" "controller" =&gt; string(4) "base" "action" =&gt; string(3) "404" "uri" =&gt; string(14) "calendar/index" "route" =&gt; object Route(5) { protected _callback =&gt; NULL protected _uri =&gt; string(6) "&lt;path&gt;" protected _regex =&gt; array(1) ( "path" =&gt; string(5) "(|.+)" ) protected _defaults =&gt; array(2) ( "controller" =&gt; string(4) "base" "action" =&gt; string(3) "404" ) protected _route_regex =&gt; string(21) "#^(?P&lt;path&gt;(|.+))$#uD" } ) </code></pre> <p>The javascript code where I call the save function is:</p> <pre><code>calendar.save_event = function() { var save_url = URL_ROOT + '/calender/save?' + TIME_STAMP; // prepare the data string var inputs = []; // get all the form elements and add them to the parameter string to be sent via ajax $('#dialog_form :input').each( function() { // only add if not a checkbox, or if it is a checkbox, then it must be checked if ( ! $(this).is(':checkbox') || $(this).is(':checked')) { inputs.push(this.name + '=' + encodeURIComponent(this.value)); } }); alert('try saving by posting to: ' + save_url); // try to save the record $.ajax({ type: 'POST', data: inputs.join('&amp;'), url: save_url, dataType: 'json', success: function(data, text_status) { if (data['status'] == 1) { alert(data['status_message']); // add the event to the calendar // todo add actual event details $("#day_number" + $('#initial_day_number').val()).append("new event"); // close the dialog box $('#dialog_form').dialog("close"); } else { alert('The event could not be saved at this time. Please try again later. (' + data['status_message'] + ')'); } }, error: function(xml_request, text_status, error_thrown) { alert('The event could not be saved at this time. Please try again later. (' + text_status + ')'); } }); } </code></pre> <p>In the above code, URL_ROOT is set correctly. I added this in because I was originally using a relative reference '/calendar/save' but neither works. I also added the TIME_STAMP GET parameter which is just the current UNIX timestamp (time() in php) to see if this was a caching issue. It also does not make any difference.</p> <p>As per the debug code, you can see that the call is going to the correct URL, it is just not getting matched for some reason.</p> <p>Any help would be greatly appreciated. </p> <p>Thanks, Craig</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload