uri_to_assoc(n) doesn't work after routing - php

So this currently loads the page for me.
/controllername/view/id/27/title/shoes
However, I want the user to be able to type in:
/controllername/27/shoes
to view the file. So in the routing file, I made a rule like this,
$route['controllername/(:num)/(:any)'] = "controllername/view/id/$1/title/$2";
The original address works with uri_to_assoc(n) because I have it as
$array = $this->uri->uri_to_assoc(3);
$id = $array['id'];
$title = $array['title'];
But once I route it and use the new address to access the file, I get the errors:
Message: Undefined index: id
Message: Undefined index: title
I do not get these errors with my original url way of accessing it. I guess the value of uri_to_assoc(3) changes once the url is changed but I thought the routing function would take care of that. Can anyone help me get rid of these variable errors?

In this case you'll want ruri_to_assoc:
http://codeigniter.com/user_guide/libraries/uri.html
$this->uri->ruri_to_assoc(n)
This function is identical to [uri_to_assoc], except that it creates
an associative array using the re-routed URI in the event you are
using CodeIgniter's URI Routing feature.
You should still validate your array indices anyways, in case the URL itself is invalid.

Related

PHP - Creating an XML file from an Object

I have a simple method inside a class that returns an Address based on a id.
For example:
$address = Address::get_by_id($id);
I'm calling the method based on a GET value. The function loads some data from the database and creates an XML file and then makes a map.
$map = new Map();
$map->create_address_xml($address);
Everything works as I expect when the URL is : /page?id=123
The problem I have is when I introduce a rewritten url.
For example
^pretty-url/([0-9]+)$ /page?id=$1 [L]
When the url is rewritten and I pass the $address object to $map->create_address_xml, it doesn't work.
I get no errors, so I'm stumped. Any suggestions?
PS. My first question on here (after much searching!) Please let me know if you need any more detail.
You can put Address fields in a json and Then convert it in XML.

How can I get array from GET request?

I have a trouble:
I have url of view:
?materials=1&materials=2&materials=3&materials=4&materials=5&materials=6
How can I get it in array throw Yii mechanism?
Yii::app()->request->getParam('materials')
Not working
$_GET['materials']
Too not working
Url is static and can not change
This URL was created https://github.com/Mikhus/jsurl plugin
PHP automatically parses parameter as an array, if it ends by []. (i.e. ?materials[]=1&materials[]=2&materials[]=3&materials[]=4&materials[]=5&materials[]=6) Otherwise you can parse query string manually to solve your issue. Look at this

Empty value of GET parameter in zend framework

I'm using zend framework in my site. URI address one of the page is:
http://mysite.com/controller/action/no/123/date//email//
I expect to obtain the next GET parameters and values:
no=>123
date=>
email=>
It's true on localhost but on the web hosting on obtained:
no=>123
date=>email
It looks like empty values was missed. What can be a reason for this and how I can it fix?
You have issue there is routes have done like first is key and next is value so, in your url have two blank space. change in url something line below.
try like this
http://mysite.com/controller/action/no/123/date/email/

Codeigniter $_GET in models?

I've got a URL parameter I need to get to pass to a PHP MySQL Variable.
Lets say for instance my URL is:
www.facebook.com/?ref=logo
Normally it'd $_GET to get the value of ref. How would I go about doing this in a CodeIgniter model? From what I understand, $_GET doesn't work with CI?
Its in the input class.
$ref = $this->input->get('ref');
Source : http://ellislab.com/codeigniter/user_guide/libraries/input.html
Get works just fine in CodeIgniter. You would access it in a similar way to POST values:
$ref = $this->input->get('ref', true);

PHP variable passing

I'm working with drupal. I have this page something.com/node/13. Inside I have this script
<?php
$door = $_GET["variable"];
echo $door;
?>
When I open the URL like this something.com/node/13?variable=1231 I get the following error:
Error message
Notice: Undefined index: variable in eval() (line 2 of /var/www/html/modules/php/php.module(74) : eval()'d code).
and no output. Any ideas what I might be doing wrong?
The error, partcilarly in drupal 7 simply means that you aren't getting any value for $_GET['variable']. This would be because the url doesn't have a value (someurl?variable=foo). You can avoid the notice by prefixing an # like this:
$door = #$_GET['variable'];
but that won't make the variable return any data. It's pretty unclear from the code you've posted what you're trying to accomplish. You might consider starting there. There is no reason why you can't use $_GET variables in drupal. I do so all the time.
Use drupal_get_query_parameters
Because the rewrite rules with Drupal, you don't grab the $_GET values cleanly directly like that.

Categories