⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

[solved] unable to add when unset_add() within a if.



Raboo
  • profile picture
  • Member

Posted 19 September 2012 - 08:10 AM

Hi,

I'm unable to do a add or delete when I have this code..


function node($deleted = false)
{
--snip--

if ($deleted) {
$crud->unset_add();
$crud->unset_delete();
}
}



So the $deleted should be false when running main/node without setting it to true. But I'm unable to delete or add. Get this error:


An Error Was Encountered
You don't have permissions for this operation --- #0 /var/www/vhosts/xxx/html/application/controllers/main.php(237): grocery_CRUD->render() #1 [internal function]: Main->node('add') #2 /var/www/vhosts/xxx/html/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array) #3 /var/www/vhosts/xxx/html/index.php(202): require_once('/var/www/vhosts...') #4 {main}

victor
  • profile picture
  • Member

Posted 19 September 2012 - 10:26 AM

hi! You have this error because when click to link 'delete' you will have segments in url. If you will have segmens your variable $deleted=true. Sorry. I am bad in English.

Raboo
  • profile picture
  • Member

Posted 19 September 2012 - 10:26 AM

Ok I've figured out why it doesn't work, but not how to solve it.
Because when you run add it runs node("add");
so the var changes from a bool to string(3) "add"

Raboo
  • profile picture
  • Member

Posted 19 September 2012 - 10:28 AM

[quote name='victor' timestamp='1348050374' post='3517']
hi! You have this error because when click to link 'delete' you will have segments in url. If you will have segmens your variable $deleted=true
[/quote]
Ok, how do I do this?

victor
  • profile picture
  • Member

Posted 19 September 2012 - 11:01 AM

what it is necessary for you?

victor
  • profile picture
  • Member

Posted 19 September 2012 - 11:04 AM

you can use CI's configs as solution.

Raboo
  • profile picture
  • Member

Posted 19 September 2012 - 11:46 AM

Yes it's kind of necessary to avoid having to functions with same code and keeping them in sync.

How do you mean i can use CI configs?

victor
  • profile picture
  • Member

Posted 19 September 2012 - 14:00 PM

use session. If you don't know how do it I can write example later

Raboo
  • profile picture
  • Member

Posted 20 September 2012 - 14:34 PM

I have no idea what you are talking about, the closest I guess is that i should edit some of the CI config files?

victor
  • profile picture
  • Member

Posted 20 September 2012 - 15:08 PM

Ha! Solution is simple)))

your link: site.com/controller/method/deleted

controller:


function method()
{
if($this->uri->segment(3)=='deleted')
{
$crud->unset_add();
$crud->unset_delete();
}
}

Raboo
  • profile picture
  • Member

Posted 02 October 2012 - 09:57 AM

[quote name='victor' timestamp='1348153714' post='3550']
Ha! Solution is simple)))

your link: site.com/controller/method/deleted

controller:


function method()
{
if($this->uri->segment(3)=='deleted')
{
$crud->unset_add();
$crud->unset_delete();
}
}

[/quote]

This works great! Thanks for the help