I like to preface this question by apologizing for being noob.
For codeigniter URL, format goes: example.com/class/function/ID
If I were to have the urls below
website.com/books/chapter/1
website.com/books/chapter/2
I know how to create class named "books" under which I would create public function "chapter", so...
public funtion chapter() {
$this->load->view("content");
}
How would I add the ID's 1 and 2, assuming the only difference between the two website is I would have:
1.png within my "content" for website.com/books/chapter/1 and
2.png within my "content" for website.com/books/chapter/2, with 2.png replacing where 1.png was supposed to be.
Thanks!
Since you are using this URL: website.com/books/chapter/2
, you are already passing the id after the last slash. Therefore your controller method should receive that ID as a parameter like this:
Controller:
public function chapter($id) {
$data["image_id"] = $id;
$this->load->view("content", $data);
}
View:
<img src="<?= $image_id ?>.png">
Controller:
public function chapter() {
$data["image_id"] = $this->uri->segment(3); //since your ID(number) is in third segment so 3
$this->load->view("content", $data);
}
View:
<a href="siteurl/controller/method/<?php echo $image_id;?>"><img src="<?= $image_id ?>.png"></a>
for more info on URI class https://ellislab.com/codeigniter/user-guide/libraries/uri.html
The ids are just the method parameters. You can get it by passing the parameter in your method.
In the controller:
public function chapter($id) {
$data["image_id"] = $id;
$this->load->view("your_view", $data);
}
In your view:
<img src="<?php echo $image_id;?>.png"/>