Welcome Guest, Not a member yet? Register   Sign In
function call from url
#1

[eluser]airparkroad[/eluser]
I am trying to do this one thing..

I want to type into the url, say,

../index.php/directory/product/22345

and make it appear somewhere on my web page,

product ID: 22345


How do I achieve this?


btw, code igniter rocks!!! +P
#2

[eluser]xwero[/eluser]
Code:
echo $this->uri->segment(3);
#3

[eluser]airparkroad[/eluser]
<html>
<body>
<?php echo $this->uri->segment(3); ?>
</body>
</html>

Above code is how I wrote it on directory_view.php file.
And I typed ../index.php/directory/product/23455

It gave me a 404 error.
Am I doing something wrong here?
#4

[eluser]xwero[/eluser]
do you have controller named directory and a method named product?
to test you can do following in your controller
Code:
function product()
{
   echo $this->uri->segment(3);
}
#5

[eluser]airparkroad[/eluser]
Yes. I have a controller named directory.
And I have a function named product.

How do I call the function product from the view file?

Thanks a lot for your help.
#6

[eluser]xwero[/eluser]
it's the other way around Smile
Code:
function product()
{
  $this->load->view('directory_view');
}
I would suggest you read the user guide more closely.
#7

[eluser]airparkroad[/eluser]
hmm..okay.. so..

for my controller file, called directory,,
i have functions
directory()
index() (-> this with $data)
and product()

I'm calling $this->load->view('directory_view') inside of index() function.

From directory_view file,

I do,

echo $this->uri->segment(2)
echo $this->uri->segment(3)


Then, I type ../index.php/directory/product/123

No matter what I put inside of product() function, it would give me 404 error.

But if I do ../index.php/directory/directory/123

Then it would show

directory 123.



How do I solve this problem?
#8

[eluser]xwero[/eluser]
can i see your controller
#9

[eluser]Michael Wales[/eluser]
Controller
Code:
Class Directory extends Controller {

  function __construct() {
    parent::Controller();
  }

  function product($id = '') {
    $this->load->view('directory_view');
  }

}

View:
Code:
<?= $this->uri->segment(3); ?>
#10

[eluser]airparkroad[/eluser]
Controller
Code:
<?php

class directory extends Controller {

    function directory() {
        parent::Controller();
    }


    function index() {
        $data['title'] = "Directory Title";
        $data['heading'] = "Directory Heading";

        $this->load->view('directory_view', $data);
    }
    
    function product() {
        

    }

}

?>

So what has to go into the product() function?




Theme © iAndrew 2016 - Forum software by © MyBB