Jump to content

via Ad Packs

Confused :(


  • Please log in to reply
6 replies to this topic

#1 johanmichel

johanmichel

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 14 July 2012 - 05:38 PM

Sorry for posting so fast after eachother but I would love this to work but it doesn't. All I want is my tables to load in those cool grids. So... I moved assets/grocery_crud to /views/ and modified the paths of default_theme_path in grocery_crud.php;

This is my code:

    public function affiliates()
    {
	    $crud = new grocery_CRUD();
	    $crud->set_table('accounts')
		    ->set_subject('Accounts')
		    ->columns('username','password','email','paypal_bank','lastname','address')
		    ->display_as('paypal_bank','Paypal')
		    ->display_as('lastname','Last Name');
	    $crud->fields('username','password','email','paypal_bank','lastname','address');
	    $crud->required_fields('username','password');
	    $output = $crud->render();
	    $this->_output($output);
    }

    function _output($output = null)
    {
	    $this->load->view('crud/themes/datatables/views/list.php',$output);   
    }

I get these errors:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: columns
Filename: views/list.php
Line Number: 6
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/list.php
Line Number: 6
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: unset_delete
Filename: views/list.php
Line Number: 9


Also, I tried to list_template.php instead because I thought perhaps I should call that one. But then it says:

Fatal error: Call to undefined method CI_Loader::set_css() in /home/f606/domains/f606.info/public_html/admin/application/views/crud/themes/datatables/views/list_template.php on line 4


What am I missing? What am I doing wrong?

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 926 posts
  • LocationLondon

Posted 14 July 2012 - 05:44 PM

Hello johanmichel and welcome to the forum,

Actually it is more easy than you think. You don't have to do anything, you just have to copy your files into your project and start. You don't have to move your assets to somewhere else or the views folder. They are all designed to work together without changing anything. So for example for a basic structure in CI your folder structure will look like this:

website_folder/
–––– application/
–––––––– config/
–––––––––––– autoload.php
–––––––––––– ...
–––––––––––– datatables.php
–––––––––––– doctypes.php
–––––––––––– flexigrid.php
–––––––––––– foreign_chars.php
–––––––––––– grocery_crud.php
–––––––––––– ...
–––––––– controllers/
–––––––––––– examples.php
–––––––––––– index.html
–––––––––––– welcome.php
–––––––– libraries/
–––––––––––– grocery_crud.php
–––––––––––– index.html
–––––––– models/
–––––––––––– grocery_crud_model.php
–––––––––––– index.html
–––––––– views/
–––––––––––– example.php
–––––––––––– index.html
–––––––––––– welcome_message.php
–––– assets/
–––––––– grocery_crud/
–––––––––––– css/
–––––––––––– js/
–––––––––––– texteditor/
–––––––––––– themes/
–––––––– uploads/
–––––––– index.html
–––– system/
–––– user_guide/
–––– change_log.txt
–––– example_database.sql
–––– index.php
–––– licence-grocery-crud.txt
–––– license.txt

It's easy to make it work. Just copy all the files and folders (there is also a model and a config) to your project and it will work for sure. If you have any issues just post it ;)

Codeigniter doesn't support files like CSS and JS inside the application so thats why I have the folder assets outside the application folder.

EDIT:

And something else the:
		function _output($output = null)
		{
				$this->load->view('crud/themes/datatables/views/list.php',$output);  
		}
is wrong

The right is the:
function _output($output = null)
	{
		$this->load->view('example.php',$output);  
	}

and example.php looks like:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />

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

<?php endforeach; ?>
<?php foreach($js_files as $file): ?>

	<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>

<style type='text/css'>
body
{
	font-family: Arial;
	font-size: 14px;
}
a {
	color: blue;
	text-decoration: none;
	font-size: 14px;
}
a:hover
{
	text-decoration: underline;
}
</style>
</head>
<body>
<!-- Beginning header -->
	<div>
		<a href='<?php echo site_url('examples/offices_management')?>'>Offices</a> |
		<a href='<?php echo site_url('examples/employees_management')?>'>Employees</a> |
		<a href='<?php echo site_url('examples/customers_management')?>'>Customers</a> |
		<a href='<?php echo site_url('examples/orders_management')?>'>Orders</a> |
		<a href='<?php echo site_url('examples/products_management')?>'>Products</a> |
		<a href='<?php echo site_url('examples/film_management')?>'>Films</a>

	</div>
<!-- End of header-->
	<div style='height:20px;'></div>
	<div>
		<?php echo $output; ?>

	</div>
<!-- Beginning footer -->
<div>Footer</div>
<!-- End of Footer -->
</body>
</html>

You can follow the instuctions of codeigniter installation
Posted Image

#3 johanmichel

johanmichel

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 14 July 2012 - 06:36 PM

Thanks A LOT Johny. I am going to give it a try, it seems a lot more logically :) thanks!!

#4 johanmichel

johanmichel

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 14 July 2012 - 06:51 PM

Hey Johnny, I tried what you said but example.php doesn't output the data. So I copied the contents of list.php from the assets dir to the example.php file, but that gave errors.

What I would like is the data to be loaded in the Grocery Crud grid (f.e. the one here: http://www.grocerycr...es/full_example). How can I call list.php, add.php and edit.php as a view? I tried simply to load ../assets/grocery_crud/themes/views/list.php but this results in an error.

Thanks again!

#5 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 926 posts
  • LocationLondon

Posted 14 July 2012 - 07:30 PM

no this will not work.

You have to forget for a bit how the js, css and views will load. Everything will be automatically without even do anything more.

I will explain what you have to do to make it work.
1. First of all make sure that you copy all the files and folders of grocery CRUD to your project.
2. The example.php it is actually included at the files and folder of grocery CRUD and you don't have to do anything else
3. now the only thing that you have to do is to go to your basic controller (let's say Main) and add your code there:

public function affiliates()
		{
				$crud = new grocery_CRUD();
				$crud->set_table('accounts')
						->set_subject('Accounts')
						->columns('username','password','email','paypal_bank','lastname','address')
						->display_as('paypal_bank','Paypal')
						->display_as('lastname','Last Name');
				$crud->fields('username','password','email','paypal_bank','lastname','address');
				$crud->required_fields('username','password');
				$output = $crud->render();
				$this->_example_output($output);
		}
		function _example_output($output = null)
		{
				$this->load->view('example.php',$output);  
		}

If you copy this code above and then go to /your_project/index.php/main/affiliates you can see that believe it or not your CRUD is ready. Test the edit and add (just add something to test it) and then go to step 4

4. Now that your default functionallity of grocery CRUD works I can explain you how it works. Your actually output is this:

$output->output; //Your output
$output->js_files; //Your js files
$output->css_files; //Your css files

So now you can simply add your custom view. for example:
....
$output = $crud->render();
$this->load->view('header.php',$output);
$this->load->view('my_view.php',$output);
$this->load->view('footer.php');

Then in your view you can easily take the data with simple variables like this ( header.php ):
<?php
foreach($css_files as $file): ?>
	<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />

<?php endforeach; ?>
<?php foreach($js_files as $file): ?>

	<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>

and the output easily with ( my_view.php ) :

<?php
echo $output; // Your datagrid, your add form your edit ... e.t.c. will be here automatically so don't worry about them
?>

You don't need anything more. As I understood you are new to Codeigniter so firstly you have to understand that for example if you have any array or object (in our case is an object) the array/object transforms into variables for the view. For example if you have:

$output = (object)array('test1' => 'Test 1', 'test2' => 'Test 2');
$this->load->view('test.php',$output);

in the view you have to call the variables like this:

<?php
echo $test1; // Test 1
echo $test2; // Test 1
?>

If this still didn't work for you try to:
1. download the Codeigniter again from the beginning and open a new project
2. Copy all the files and folder of grocery CRUD as I told you
3. Go to phpmyadmin and create a new database let's name it "test_database"
4. Import the example database at: examples_database.sql
5. Configure your database file from application/database.php
6. And now go to open your_project/index.php/examples and click to the links to see grocery CRUD in action. This is a good start because at least you will have a working example and you can play with this example. (All the examples are at the controller examples.php )

I hope it helps. If you are still have problems don't hesitate to send a post. That's why this forums is all about ;)
Posted Image

#6 johanmichel

johanmichel

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 14 July 2012 - 08:19 PM

Wow I am impressed by the time you took to explain me all this!! Thanks so so much! First of all I'm going to do a clean CI and GC install and run the /examples/ to understand it better. Thanks a lot!

#7 johanmichel

johanmichel

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 14 July 2012 - 08:45 PM

Awesome, its working perfectly now. I simply looked at the examples pages (somehow these werent copied in the first instance). I LOVE it, GC is great and will save me A LOT of work! Thanks so much!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users