Welcome Guest, Not a member yet? Register   Sign In
Getting the URL to work
#1

[eluser]ptechie[/eluser]
Hello all...

First of all, I am looking at Code Ignitor for the first time... so please excuse the novice questions and help if you can.

I've got a page under the base URL, treatments which works when clicked from the homepage.

I found this code, in app/controllers/index.php

Quote:
function treatments()
{
$this->setPageTitle('Treatments');
$this->load->template('index/treatments.phtml', $this->data);
}

Now, there is a link on this page (treatments) that links to <base url>/cancer

I've got the cancer.phtml file stored in app/views/index/ (that is where the treatments.phtml is stored)

ISSUE: The page <base url>/cancer does not show up, I get a 404.

HELP!

Thanks
#2

[eluser]zimco[/eluser]
Taking a wild stab at your problem, i'm a newbie too, but is there any reason why you are using the .phtml extension for your files rather than the good-old .php file extension?

I'd try changing that first....
#3

[eluser]ptechie[/eluser]
Well, that's how the application has been setup.
With the reading that I did, I don't think that would cause the issue... also all the other pages that are working fine are also .phtml.

Thanks
#4

[eluser]Matthew Lanham[/eluser]
You need to add the function cancer() into your controllers from what i can see, CI will not automatically pick up new views...
#5

[eluser]ptechie[/eluser]
I should have mentioned, I have done this

Quote: function cancer()
{
$this->setPageTitle('Cancer');
$this->load->template('index/cancer.phtml', $this->data);
}

Thanks
#6

[eluser]zimco[/eluser]
Well if .phtml works for you then the only other thing that looks different to me is the
$this->data in the load view statement.

I've had good luck doing it like:
Code:
$this->load->view('some_view', $data);

where $data is an array or an object.
#7

[eluser]ptechie[/eluser]
zimco - I tried that and it didn't help. Also, like I mentioned that the other pages are working fine.

Hope, someone could explain how this works... what are the elements I need to make the pages to show up?
#8

[eluser]Pascal Kriete[/eluser]
Usually it's quite simple, but it sounds like the application your working on has been changed a bit.

The normal way:
Take all the variables you need in your view and put them in an associative array, such as:
Code:
$view_vars = array('test' => $var, 'test2' => 'cool');
(it could be $this->view_vars, $jj->mydingojumps, or anything else - as long as it's a valid array)

Then load your view using:
Code:
$this->load->view('view', $view_vars);

If you don't need any variables in your view you can omit that parameter.
The variables are extracted, so that in your view you now have access to $test and $test2.

I would suggest you find the template function and figure out what it does differently. Apart from using a different extension.
#9

[eluser]ptechie[/eluser]
Thanks to everyone who responded...

I found that there is a file (./app/config/routes.php), where I needed to enter
Quote:$route['cancer'] = "index/cancer";

Thank you once again.




Theme © iAndrew 2016 - Forum software by © MyBB