Welcome Guest, Not a member yet? Register   Sign In
Help needed: problem setting a specific url
#1

[eluser]adelregh[/eluser]
Hi there,

I have a controller called "faculty" which has 7 functions one of which is called "profile"
I also have one view that wraps all these functions in a sidebar

Now when, for example, the profile is tapped it opens perfectly but I want to change the URL from:

.../faculty/profile

To:

.../faculty/#/profile

Where # is going to be variable
#2

[eluser]InsiteFX[/eluser]
./application/config/routes.php

Code:
$route['faculty/(:any)'] = "faculty/$1/profile";

But this really depends on what you are really trying to do in your Controller.
#3

[eluser]adelregh[/eluser]
Thanks for your reply

Here is my code:
In the controller:

Code:
public function index()
{
$this->load->view('adel');
}

public function profile()
{

$id = $this->uri->segment(2);
$query = $this->db->query('SELECT * FROM faculty WHERE SSN = 1;');
$data['name'] = '';
$data['section'] = "Profile";
$data['query'] = $query;

$this->load->view('adel', $data);

}

public function publications()
{

$query = $this->db->query('SELECT P_ID, TITLE FROM publications WHERE SSN = 1;');
$data['name'] = '';
$data['section'] = "Publications";
$data['query'] = $query;

$this->load->view('adel', $data);
}

Eventually instead of SSN = "1", I wanna take the variable from the URL

In the view I have something like this:

Code:
<div id="wrapper">

&lt;!-- Sidebar --&gt;
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand">
<a href="member"> KU Faculty</a>
</li>
<li>
<hr  color:#000;margin-right:30px;'>
</li>
<li>
<a href="profile">My Profile</a>
</li>
<li>
<a href="research">Reseasrch</a>
</li>
<li>
<a href="teaching">Teaching</a></li>
</li>
<li>
<a href="experience">Experience</a></li>
</li>
<li>
<a href="publications">Publications</a>
</li>
<li>
<a href="resume">Resume</a>
</li>
<li>
<a href="about">About us</a>
</li>
</ul>
</div>
&lt;!-- /#sidebar-wrapper --&gt;

&lt;!-- Page Content --&gt;
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<h1> &lt;?=$section ?&gt; </h1>
<h3> &lt;?= $name ?&gt; </h3>

&lt;?php

switch ($section)
{

case 'Publications':
foreach ($query->result() as $row)
{
echo "<span  Cooper Black;font-weight:bold'>$row->P_ID</span>";
echo ": ";
echo "<span  Georgia'>$row->TITLE</span>";
echo "<br>" . "<br>";
}
break;

case 'Research':
foreach ($query->result() as $row)
{
echo $row->INTEREST_AREA;

}
#4

[eluser]adelregh[/eluser]
I got it working but I have one small issue. Please help

When I click on a user's profile (sidebar taps) the URL will be:
..../profile/3
Now when I click on his experience the URL will change to:
..../experience

Is there any way that I can keep the last segment so that the URL will be:
..../experience/3
I need the number to be there so that I can use $this->uri->segment();

Any suggestions would be greatly appreciated.
#5

[eluser]CroNiX[/eluser]
Just add the ID to where you are creating the link?
#6

[eluser]adelregh[/eluser]
The ID is not fixed it is a variable
#7

[eluser]CroNiX[/eluser]
Well, yes, but how are you generating your /profile/3 urls, where I assume the 3 is a variable?




Theme © iAndrew 2016 - Forum software by © MyBB