Reputation: 1332
I have been working on a dynamic viewloader and I ran into some problems. Eventhough it's working fine when I get an "edit" I can't seem to fix the code in a nice way once I get to an add.
The current viewLoader looks as follow: http://pastebin.com/e9piMJBW
The problem I'm getting is that at line 45:
$values['data'] = $this->DoQuery($url[(count($url) - 3)], $url[(count($url) - 2)], $url[(count($url) - 1)]);
I'm always expecting my url to be as : domain.com/something/users/edit/55.
Where the last 3 segments of my URL would define what to do.
users => Table
Edit => function and
55 would be the ID of the user.
I use this for my admin panel so it will automaticly get / insert data depending on the URL and $_POST values.
My question is that once I have an add this senario will be different. The URL will look as follow:
domain.com/something/users/add
I will no longer have all 3 values (as expected with edit / delete)
Upvotes: 0
Views: 170
Reputation: 187
Your problem at line 45 could be solved as follows :
function generateUrl(){
$this->load->helper("url");
$url = explode("/", $this->uri->uri_string());
$values = array();
if (count($url) == 5 ) {// Edit of Delete
$values['data'] = $this->DoQuery($url[(count($url) - 3)], $url[(count($url) - 2)], $url[(count($url) - 1)]);
}
else { //Add
$values['data'] = $this->DoQuery($url]count($url)-2)],$url[(count($url) -1)]);
}
......
Upvotes: 2