⚠ 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

grocery with boilerplate



maru
  • profile picture
  • Member

Posted 03 January 2013 - 22:02 PM

Hi everyone!


[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]I was trying to integrate codeigiter and grocery and boilerplate.[/font][/color]

[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]I created an controller [b]home[/b][/font][/color]


<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Heredamos de la clase CI_Controller */
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$data = array('title' => 'homepage', 'main_content' => 'home_v');
$this->load->view('template', $data);
}
}



[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]then I created a folder "includes" with 2 files: [b]header and footer[/b] (in views)[/font][/color]
[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]and also in views my template and a file home_v with some text just to know if my example was working.[/font][/color]

[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif][b]template.php[/b][/font][/color]


<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>$title</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="<?php echo base_url('css/normalize.css'); ?>">
<link rel="stylesheet" href="<?php echo base_url('css/main.css'); ?>">
<script src="<?php echo base_url('js/vendor/modernizr-2.6.2.min.js'); ?>"></script>
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div id="container">
<header>
<?php $this->load->view('includes/header'); ?>
<?php $this->load->view('includes/menu'); ?>
</header>

<div id="main" role="main">
<?php $this->load->view($main_content); ?>
</div>


<footer>
<?php $this->load->view('includes/footer'); ?>
</footer>
</div>
<!-- fin container -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.3.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>


[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]After that a new controller [b]categorias[/b][/font][/color]



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* Heredamos de la clase CI_Controller */
class Categorias extends CI_Controller {

function __construct()
{

parent::__construct();

/* Cargamos la base de datos */
$this->load->database();

/* Cargamos la libreria*/
$this->load->library('grocery_crud');

/* Añadimos el helper al controlador */
$this->load->helper('url');
}

function index()
{

$data = array('css_files' => array('main.css'));
$this->load->view('categorias/categorias_v', $data);

$data = array('title' => 'categorias', 'main_content' => 'categorias/categorias_v');
$this->load->view('template', $data);

}

/*
*
**/
function categorias_v()
{
try{

/* Creamos el objeto */
$crud = new grocery_CRUD();

/* Seleccionamos el tema */
$crud->set_theme('flexigrid');

/* Seleccionmos el nombre de la tabla de nuestra base de datos*/
$crud->set_table('categorias');

/* Le asignamos un nombre */
$crud->set_subject('Categorias');

/* Asignamos el idioma español */
$crud->set_language('spanish');

/* Aqui le decimos a grocery que estos campos son obligatorios */
$crud->required_fields(
'id_categoria',
'nombre_categoria'
);

/* Aqui le indicamos que campos deseamos mostrar */
$crud->columns(
'id_categoria',
'nombre_categoria'
);

/* Generamos la tabla */
$output = $crud->render();


}catch(Exception $e){
/* Si algo sale mal cachamos el error y lo mostramos */
show_error($e->getMessage().' --- '.$e->getTraceAsString());
}
}
}



[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]but this is not working, I have some errors[/font][/color]


[font=Helvetica, 'Helvetica Neue', Arial][size=4][b] A PHP Error was encountered[/b]

Severity: Notice
Message: Undefined variable: js_files
Filename: categorias/categorias_v.php
Line Number: 5[/size][/font]

[font=Helvetica, 'Helvetica Neue', Arial][size=4][b] A PHP Error was encountered[/b]

Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: categorias/categorias_v.php
Line Number: 5[/size][/font]

[font=Helvetica, 'Helvetica Neue', Arial][size=4][b] A PHP Error was encountered[/b]

Severity: Notice
Message: Undefined variable: output
Filename: categorias/categorias_v.php
Line Number: 9[/size][/font]
[font=Helvetica, 'Helvetica Neue', Arial][size=4] header menu


[b] A PHP Error was encountered[/b]

Severity: Notice
Message: Undefined variable: js_files
Filename: categorias/categorias_v.php
Line Number: 5

[b] A PHP Error was encountered[/b]

Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: categorias/categorias_v.php
Line Number: 5

[b] A PHP Error was encountered[/b]

Severity: Notice
Message: Undefined variable: output
Filename: categorias/categorias_v.php
Line Number: 9[/size][/font]


[color=#000000][font=Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif]hope someone can help me, thanks in advance![/font][/color]