CodeIgniter Forums
url values - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: url values (/showthread.php?tid=25429)

Pages: 1 2


url values - El Forum - 12-11-2009

[eluser]hamzakhan[/eluser]
i want to post two variable with two values in this anchor tag in CI.
and also want to access or get on other page.
Code:
<?=anchor('admin/subcatagory/Delete/?subcatID='.$subcatagory[$i]->cat_id,img(base_url().'/catId=123'.'/assets/images/common/b_drop.png'))?>
Please tell me is it a right way to do this.and how i can get thse values on there page..


url values - El Forum - 12-11-2009

[eluser]jwindhorst[/eluser]
I prefer using clean URL's to using a query string. So the way that I would handle this would be:
Code:
<?= anchor("admin/subcatagory/Delete/$subcategory[$i]->cat_id/catId=123 ?>

and then reference them with
Code:
$this->load->helper('url');
$category_id=$this->url->segment(4);

Hope that helps


url values - El Forum - 12-11-2009

[eluser]theprodigy[/eluser]
by default, CodeIgniter is setup to use urls like:
Code:
http://domain.tld/controller/method/arg1/arg2/arg3/etc/etc

The documentation for the anchor tag that you are using can be found HERE.

This uses the url helper, so make sure you have that loaded first (either manually, or autoload).

In your config file, you can setup CodeIgniter to use a normal query string if you so choose. Information on that can be found HERE

To access the urls on the linked to page, you would use:
1. Method parameters (where each URL argument falls in line with a parameter in the method declaration - arg1 = first method parameter, arg2 = second parameter, etc),
2. Any of the options listed HERE, if using the default CodeIgniter configuration,
3. Or you can use the normal PHP $_GET way.


url values - El Forum - 12-11-2009

[eluser]hamzakhan[/eluser]
thanks for all infor or help.

n
is there any way to make this url
http://localhost/server/sscart/admin/subcatagory/id/130

to

http://localhost/server/sscart/admin/subcatagory/
and value 130 will also accessed.


url values - El Forum - 12-11-2009

[eluser]theprodigy[/eluser]
that's not a typical way of handling it, but yes, I believe their is a way.
The only way I know to do that is to make each link a form submission, and pass the 130 in through a hidden form element.
Doing it this way, you would access the 130 through
Code:
$this->input->post('[name of hidden form element]');
rather then through any url accessing code.

Is there a reason you don't want that part in your url?


url values - El Forum - 12-12-2009

[eluser]hamzakhan[/eluser]
yeah thre is a reason tht url contain the method name id which is showing the idof evy catagory.
due to this if you just change the id u can see evey catagory info by only changeing the id number
like id/12 or id / 3 whichc i dont want in my url.


url values - El Forum - 12-12-2009

[eluser]theprodigy[/eluser]
You can always create a second unique string field in your database, and build your urls off of that
instead of:
Code:
http://www.domain.tld/catalog/category/1
you could have:
Code:
http://www.domain.tld/catalog/category/green_shirts
and since you only have one row with that entry (since it's unique), you can base your query off of that.


url values - El Forum - 12-12-2009

[eluser]hamzakhan[/eluser]
http://www.domain.tld/catalog/category/green_shirts
yeah this is what i want.
but how i can do this.


url values - El Forum - 12-12-2009

[eluser]theprodigy[/eluser]
just create another column in your database 'items' table and make sure you set it up as string and unique.
when you do your queries, just base your queries off of that column instead of id.

if you name your column 'code', then your model would have something like
Code:
public function get_items($code) {
    $this->db->select('[put your wanted fields here]');
    $this->db->from('[table name goes here]');
    $this->db->where('code',$code);
    return $this->db->get();
}

and your controller would have something like
Code:
public function category($code) {
    $this->load->model('[model name]');

    $data['items'] = $this->[model name]->get_items($code);

    $this->load->vars($data);
    $this->load->view('[view name]');
}



url values - El Forum - 12-12-2009

[eluser]hamzakhan[/eluser]
thanks.
u r gr8