⚠ 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

Problem with insert/edit/delete functions



Wathfea

Wathfea
  • profile picture
  • Member

Posted 06 June 2012 - 23:43 PM

Hello everyone,

Maybe someone could help me.
I'm quite new in CI and mostly in groceryCRUD.
I started a new project with a few changes which make it different from the core version of the CI.
I mean I added a modul support for the core, so now I can arrange my modules a better HMVC way. I think....

Here is my app:

application
--config
--modules
----login
------controllers
--------login.php
------models
--------membership_model.php
--------grocery_crud_model.php
------views
--------all_user.php
--------logged_in_area.php
--------login_form.php
--------signup_form.php
--------signup_successful.php
----site
------controllers
--------site.php
------models
------views

and so on.

So every module has one MVC

I added the CRUD to my login module because in one page I would like to list all of the users, and want a function to add/insert/edit them.

here is a code snippet from the login.php controller:

function all() {
$this->grocery_crud->set_table('users');
$output = $this->grocery_crud->render();
$data['grid'] = $output;
$data['main_content'] = 'all_user';
$this->load->view('includes/template', $data);
}


And here is a view:

<?php $this->load->view('includes/templates/header_menu');?>
<div id="banner-wrap">
<div id="banner" class="container_24 rounded">
<div id="content_inside">
<h2>Felhasználók</h2>
<?php
echo $grid->output;
?>
</div>
</div>
</div>
<!-- end banner-wrap -->


The grid is showing up so it's good and when I want to edit/insert/delete all the functions are working. The problem is when I do an action after on the next page my site is brokeing down.

So here is the page: http://localhost/7sa....php/login/all/
I insert a row and my page redirect here: http://localhost/7sa...ogin/all/insert
And here I just got a white page with one textarea with this content in it:

[quote]
{"success":true,"insert_primary_key":6,"success_message":"<p>Az adatok sikeresen elmentve az adatb\u00e1zisba. <a href='http:\/\/localhost\/7sa\/index.php\/login\/all\/edit\/6'>Szerekszt <\/a> vagy <a href='http:\/\/localhost\/7sa\/index.php\/login\/all'>Vissza a list\u00e1hoz<\/a><\/p>","success_list_url":"http:\/\/localhost\/7sa\/index.php\/login\/all\/success\/6"}
[/quote]

Why it is happening?
Could someone help me?

P.s.: I added two printScr where you can see what is my problem

[attachment=195:working.png]

[attachment=196:error.png]

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 07 June 2012 - 08:57 AM

Hi!

I have encountered a similar problem when my javascript files did not work correctly. Have you got any errors with loading js? What says firebug?

Wathfea

Wathfea
  • profile picture
  • Member

Posted 07 June 2012 - 14:46 PM

Hi!

I checked it and I got 2 errors just after when I try to edit something:
jQuery is not defined [img]chrome://firebug/content/blank.gif[/img]
})(jQuery)
in jquery.numeric.js 142. line
and in jquery.form.js 825. line

when I hit edit at the end of the form it is redirect me to the login/all/update/6 page where i can see a white page with this code in a textarea.

{"success":true,"insert_primary_key":true,"success_message":"<p>Az adatok sikeresen elmentve <a href='http:\/\/localhost\/7sa\/index.php\/login\/all'>Vissza a list\u00e1hoz<\/a><\/p>","success_list_url":"http:\/\/localhost\/7sa\/index.php\/login\/all\/success\/6"}


I checked it with a brand new CI install without HMVC mod and it's working fine.
I checked it with the given example files because I thought the problem is my HMVC but it seems not.
So the problem have to be in my login controller.
Here is the code.
http://pastebin.com/uZBSwz3L

The function all() maybe wrong.
And here is the view.
http://pastebin.com/UgsGC4bY

And my site header view:
http://pastebin.com/W6GiF2mm

Maybe the js files are not loaded well?

Edit:

Ok I found that my jquery libary file loaded last. So I changed the order in the header but I still got one error on the page and after the post, I redirected to a blank white page.
So now my header looks like this:

<!DOCTYPE HTML>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8">
<!--[if IE]><![endif]-->
<script>
document.documentElement.className = 'js';
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<link rel="shortcut icon" href="/favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Merriweather' rel='stylesheet' />
<link rel="stylesheet" href="<?php echo base_url();?>/css/style.css" />
<link rel="stylesheet" href="<?php echo base_url();?>/css/menu.css" />
<link rel="stylesheet" href="<?php echo base_url();?>/assets/grocery_crud/themes/flexigrid/css/flexigrid.css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="<?php echo base_url();?>/assets/grocery_crud/themes/flexigrid/js/cookies.js"></script>
<script src="<?php echo base_url();?>/assets/grocery_crud/themes/flexigrid/js/flexigrid.js"></script>
<script src="<?php echo base_url();?>/assets/grocery_crud/themes/flexigrid/js/jquery.form.js"></script>
<script src="<?php echo base_url();?>/assets/grocery_crud/themes/flexigrid/js/jquery.numeric.js"></script>

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="js/selectivizr.js"></script>
<![endif]-->
<title> 7 seasons apartman menedzsment v1.0 by David Perlusz </title>
</head>
<body>

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 07 June 2012 - 17:39 PM

Hi again!

I'm not sure, but try to change this line in your header:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>


into this (jquery [b]version 1.7.1[/b], cause of grocery_crud use it as default)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>


If this doesn't help, then the problem in your controller, I think. By the way, I do not understand, how do you load grocery_CRUD library in the controller? If there is any php error, it can influence on your javascripts and break them. Do you have any php error or warning?

And the last question: what kind of library do you use for HMVC? I notice that your controller extends default CI_Controller.

Wathfea

Wathfea
  • profile picture
  • Member

Posted 07 June 2012 - 19:32 PM

Greatings!

I changed the lib but it doesn't make any change. After it I realized I have to jquery lib calls so I reduced it. My fault.
Now the numeric and form error's disappeared in Firebug.

I loaded the grocery_CRUD libary in the autoload config file.

I loaded it now directly to the login.php Controller.

When I checking the Firebug in this page no errors at all.
http://localhost/7sa...x.php/login/all
Grid shows up, working well.
When I try to edit in this page
http://localhost/7sa...ogin/all/edit/6
I got one error:

unique_hash is not defined
var cookie_crud_page = readCookie('crud_page_'+unique_hash);
flexgrid.js 153. line

At the next step when I submit the Modify a blank page load
http://localhost/7sa...in/all/update/6
with the same textarea.

I doesn't have any idea.

What is sure not the HMVC makes the trouble because the examples working well.
So my login controller made some mistakes I think.
Anyway i'm using this one https://bitbucket.or...-hmvc/wiki/Home

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 07 June 2012 - 20:13 PM

Hmm, it seems to me that the problem is in js files. But it may be the result of other problem. Have to think...

Wathfea

Wathfea
  • profile picture
  • Member

Posted 07 June 2012 - 20:40 PM

[quote name='noskov.biz' timestamp='1339100007' post='2191']
Hmm, it seems to me that the problem is in js files. But it may be the result of other problem. Have to think...
[/quote]

You are in a good way. I solved it.

Here is the solution.

I have just realized different type of grids need different js files so I can't import only the few what I saw in document inspector.
Now I added this to my view:

<?php
foreach($grid->css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($grid->js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>


Everything working fine.
Anyway really thanks for your help and guide!

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 07 June 2012 - 20:44 PM

Nothing thanks to. I'm glad for you and everything is ok :)

Elminson De Oleo Baez

Elminson De Oleo Baez
  • profile picture
  • Member

Posted 23 August 2012 - 16:12 PM

Hi,, mi problem was with the add function,

im using the theme datatables

$crud->set_theme('datatables');

and the problem was in the file /var/www/html/assets/grocery_crud/themes/datatables/js/datatables-add.js

have in line 23

alert(data.success);

i commnet it and the problem was solved

//alert(data.success);

i hope this help some one

goFrendiAsgard

goFrendiAsgard
  • profile picture
  • Member

Posted 25 August 2012 - 01:47 AM

Great. This is also solved my problem. I wonder what's wrong with jquery 1.2 ...

Pikiwix

Pikiwix
  • profile picture
  • Member

Posted 13 March 2013 - 09:41 AM

Hello guys, 

 

I have the same issue and I'm working on it !!

 

I found the reason : you probably load your application with templates (header, footer, ...)

 

So if you load your header in __construct(), it doesn't work correctly because the program don't reload and apply .js files

 

ultimately, you the crud don't have all functions to work correctly.

 

We do find a way to load our header in an other way

 

Sorry for my bad english (I'm french)

 

I hope I help you

 

Bye