• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help with $_GET['page']...

#1
[eluser]BoyBlue[/eluser]
I have this code working on a project outside of CI
(I had to replace href with *stuff* to get this to post)

Code in my *View* Page:

<ul class="navbar">
<li class="button"><a stuff="index.php">Home</a></li>
<li class="button"><a stuff="index.php?page=BlogPosts">Blog Posts</a></li>
<li class="button"><a stuff="index.php?page=Photos">Photos</a></li>
<li class="button"><a stuff="index.php?page=Issues">Issues</a></li>
</ul>



*Controller* page Code:

if($_GET['page'] == "BlogPosts"){
include("views/blogposts.php");


}else if($_GET['page'] == "Photos"){
include("views/photos.php");

}else if($_GET['page'] == "Issues"){
include("views/issues.php");

}else{

include("views/home.php");
}


****Now here is My failed attempt at CI:****

View Code:

<ul class="navbar">
<li class="button"><a stuff="index.php">Home</a></li>
<li class="button"><a stuff="index.php?page=BlogPosts">Blog Posts</a></li>
<li class="button"><a stuff="index.php?page=Photos">Photos</a></li>
<li class="button"><a stuff="index.php?page=Issues">Issues</a></li>
</ul>

Controller Code:

if ($this->input->get('page') == 'BlogPosts'){
$this->load->view('view_blog_posts');
}
elseif ($this->input->get('page') == 'Photos'){
$this->load->view('view_photos');
}
elseif ($this->input->get('page') == 'Issues'){
$this->load->view('view_issues');
}
else{

$this->load->view('view_home');

}


The error that I'm getting is *404 Page Not found*.

What am I doing wrong? Also, is there a better way to do this inside CI?

thx,
Ryan

#2
[eluser]umefarooq[/eluser]
First CI is not supporting GET for security reason for this you have to use URI class will help you. in your controller

Code:
$view = 'view_home';
$page = $this->uri->segment(2,'home');
$view = 'view_'.strtolower($page);
$this->load->view($view);

your URI will be like this
index.php/blogpost
index.php/photos
index.php/issues

no need to use more if conditions if you are using small letter then no need to use strtolower while joining string

Please read doc
URI Class
http://ellislab.com/codeigniter/user-gui...s/uri.html

Input class
http://ellislab.com/codeigniter/user-gui...input.html

#3
[eluser]InsiteFX[/eluser]
CI 2.0 has $_get.

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.