Welcome Guest, Not a member yet? Register   Sign In
Load a page like "$_REQUEST"
#1

[eluser]Raffaele[/eluser]
Hi everyone, I'm a newbie with CI and I am trying to do the porting of a website from its "old style" to CI, but I wouldn't like to change all the website's structure.
I have some questions about the links.
My actual situation is an index page with header, footer and menu, that has a central area where a traditional
Code:
require($_REQUEST['page']);
is done. The menu links are all like
Code:
index.php?page=myPage
How can I do the same thing with CI ? Using views and controllers... ?
Thanks in advance for your help.
#2

[eluser]Rob @ iFetch[/eluser]
If you don't want to change the links on your page, I would suggest creating either a controller for each page, or a central 'page' controller, and having a function for each page. Then just have a .htaccess mod_rewrite set up to redirect your current URL to a CI-friendly one.

I.e.

Controller: page
Function: myPage

URL (in browser): http://mysite.com/index.php?page=myPage
URL (as redirected by htaccess) http://mysite.com/page/myPage
#3

[eluser]Raffaele[/eluser]
Thanks for your help.
I can change the links, no problem. What I wouldn't change is the actual "structure", where I have the index page that "hosts" the content in its designated area.
I can change the menu's links if it is necessary to better achieve the MVC paradigm and the CodeIgniter way of making links.

What I am missing here is where and how I have to put the "p=MyPage" variable to pass it to the View.
e.g. in the index View I have to write something like $this->load->view(MyPage) where MyPage changes every time. Is this variable passed by the Controller of the other pages or by the Controller of the Index page or what else?
thanks again
#4

[eluser]Rob @ iFetch[/eluser]
[quote author="Raffaele" date="1292593106"]Thanks for your help.
I can change the links, no problem. What I wouldn't change is the actual "structure", where I have the index page that "hosts" the content in its designated area.
I can change the menu's links if it is necessary to better achieve the MVC paradigm and the CodeIgniter way of making links.

What I am missing here is where and how I have to put the "p=MyPage" variable to pass it to the View.
e.g. in the index View I have to write something like $this->load->view(MyPage) where MyPage changes every time. Is this variable passed by the Controller of the other pages or by the Controller of the Index page or what else?
thanks again[/quote]

Oki doki,

In that case, you could use URL's such as /page/myPage, set a route like $route['page/(:any)'] = "page/index/$1", and in your page/index function, use $this->load->view($this->uri->segment(3)).
#5

[eluser]Raffaele[/eluser]
I've tried.. there's something wrong in my approach. Here's the situation:

config/routes.php
Code:
...
$route['page/(:any)'] = "page/index/$1";

Controller of the Index page:
Code:
function index()
    {
        $this->load->view($this->uri->segment(3));
    }

it returns this error when I load the index page:

An Error Was Encountered
Unable to load the requested file: .php


and then, I don't know how to set the index view to load the content in the proper area...
I am sorry if I'm bothering you...
#6

[eluser]Rob @ iFetch[/eluser]
Have you loaded the URI library? (either auto-loaded or with $this->load->library('uri'); )

EDIT: disregard that, I forgot it's loaded automatically...

Can you try:

$a = $this->uri->segment(3);
print_r($a)

And advise what it returns.

EDIT2:

Also, if you try to access /page/ for example, it will error without having an if/else to check for a valid page name.
#7

[eluser]Raffaele[/eluser]
[quote author="robfromnewy" date="1292596607"]Have you loaded the URI library? (either auto-loaded or with $this->load->library('uri'); )

EDIT: disregard that, I forgot it's loaded automatically...

Can you try:

$a = $this->uri->segment(3);
print_r($a)

And advise what it returns.
Quote:Where should I try it ?

EDIT2:

Also, if you try to access /page/ for example, it will error without having an if/else to check for a valid page name.[/quote]
Quote:I will put "if" checks once I know it works at least a little bit Wink
#8

[eluser]Rob @ iFetch[/eluser]
Whoops! That's my bad - it should be segment(2) not 3!
#9

[eluser]Raffaele[/eluser]
[quote author="robfromnewy" date="1292597016"]Whoops! That's my bad - it should be segment(2) not 3![/quote]
Quote:It doesn't output anything.. neither with segment(3) nor segment(2)... Sad
#10

[eluser]Rob @ iFetch[/eluser]
What URL are you using?




Theme © iAndrew 2016 - Forum software by © MyBB