ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

v 1.3.3 grocery CRUD - an automatic Codeigniter CRUD

April 11, 2011 3:24am

Subscribe [77]
  • #46 / Apr 25, 2011 10:40am

    web-johnny

    235 posts

    Hmmm OK, this solve the problem but what about my layout? Now I’m only have the CRUD and I want, of course, the layout working togheter. Any way? Also I can see that you use Flexigrid 😉 where I can change default settings? I don’t want this to be collapsible

    Cheers and thanks for your support

    To your layout you can use your own template . For example in you layout_login_header you can have ( I just copy paste the home page of codeigniter ):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html > 
    <head> 
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
        <title>CodeIgniter - Open source PHP web application framework</title> 
        
        <link rel="shortcut icon" href="/images/design/favicon.ico" type="image/x-icon" /> 
        <link rel="home" href="http://codeigniter.com/" title="Home" /> 
     
        <link rel="stylesheet" href="http://codeigniter.com/?css=global/styles.css.v.1296267222" type="text/css" media="screen, projection" charset="utf-8" /> 
        <link rel="stylesheet" href="http://codeigniter.com/?css=global/sIFR-screen.css.v.1284169231" type="text/css" media="screen, projection" charset="utf-8" /> 
        <link rel="stylesheet" href="http://codeigniter.com/?css=global/sIFR-print.css.v.1284169231" type="text/css" media="print" charset="utf-8" /> 
     
        <meta name="MSSmartTagsPreventParsing" content="true" /> 
        <meta http-equiv='expires' content='-1' /> 
        <meta http-equiv='pragma' content='no-cache' /> 
        <meta name='robots' content='all' /> 
        <meta name='description' content='CodeIgniter: an open source Web Application Framework that helps you write PHP programs' /> 
        <meta name="keywords" content="EllisLab CodeIgniter PHP CMS Content Management System software framework " /> 
        
        <!-- REQUIRED CODE goes here-->
        <!-- END OF REQUIRED CODE-->
    
            <!-- Reverse Links from EllisLab network sites -->        
        <link rev="expressionengine" href="http://expressionengine.com/"
        title="The most flexible publishing system you'll ever meet" /> 
        
        <link rev="pmachinepro" href="http://pmachinepro.com/"
        title="Flexible and free blogging system that supports advanced features like multiple blogs, moblogging, and much more" /> 
        
        <link rev="ellislab" href="http://ellislab.com/"
        title="Where ideas hatch!" /> 
        
        <link rev="enginehosting" href="http://enginehosting.com/"
        title="High performance web hosting" /> 
     
            <link rel="shortcut icon" href="/images/design/favicon.ico" type="image/x-icon" /> 
        
        [removed][removed] 
        [removed] 
          var scene = {
            src: '/images/sifr/scene.swf'
          };
          sIFR.delayCSS  = true;
          sIFR.activate(scene);
          sIFR.replace({selector: 'h3' ,src: '/images/sifr/scene.swf' ,wmode:'transparent',css: { '.sIFR-root': { 'color': '#FF3C00' }  }  });
        [removed] 
    <link rel="alternate" type="application/atom+xml" title="Master Atom feed" href="http://codeigniter.com/feeds/atom/full/" /> 
    <link rel="alternate" type="application/rss+xml" title="Master RSS feed" href="http://codeigniter.com/feeds/rss/full/" /> 
    </head> 
     
    <body id="home"> 
     
        <div id="masthead"> 
            <a href="http://ellislab.com/">/images/design/ellislab_network.gif</a> 
        </div> 
        
     
        <div id="header"> 
        <div id="login"> 
                    <a href="http://ellislab.com/forums/member/login/">Login</a>  |  <a href="http://ellislab.com/forums/member/register/">Register</a> 
            </div> 
        <h1><a href="/" title="CodeIgniter">/images/design/ci_logo2.gif</a></h1> 
    </div> 
     
     
        <div id="siteNav"> 
        <ul> 
            <li id="homenav"><a href="http://codeigniter.com/">Home</a></li> 
            <li id="downloadsnav"><a href="http://codeigniter.com/downloads/">Downloads</a></li> 
            <li id="newsnav"><a href="http://codeigniter.com/news/">News</a></li> 
            <li id="tutorialnav"><a href="http://codeigniter.com/tutorials/">VideoTutorials</a></li> 
            <li id="manualnav"><a href="http://ellislab.com/codeigniter/user-guide/">User Guide</a></li> 
            <li id="forumnav"><a href="http://ellislab.com/forums/">Forums</a></li> 
            <li id="wikinav"><a href="http://codeigniter.com/wiki/">Wiki</a></li> 
            <li id="bugnav"><a href="http://bitbucket.org/ellislab/codeigniter-reactor/issues?kind=bug">Bug Tracker</a></li> 
        </ul> 
        <div class="clear"></div> 
    </div> 
        
        <!-- Candy comes in a wrapper --> 
        <div id="wrapperWit">
  • #47 / Apr 25, 2011 10:43am

    ReyPM

    86 posts

    I have it but you don’t understand me. See the image at: http://www.dropmocks.com/mUTRn. As you can see only the template related to CRUD appears so how I can maintain my layout and use CRUD at the same time. Understand now?

  • #48 / Apr 25, 2011 10:44am

    web-johnny

    235 posts

    The same thing you can do it for the footer for example :

    </div>.....
    <div>Footer .....</div>....
    </div>
    </body>
    </html>

    I have created only two themes (flexigrid and datatables). If you want to create your own crud layout (like flexigrid) it needs work and I haven’t documented the “Create your own theme” yet. But I think if you have your own cms template you will not have any problem with flexigrid or datatables.

  • #49 / Apr 25, 2011 10:51am

    ReyPM

    86 posts

    You have to this code to your template : (templates/frontend/custom-cms/template.php).

    Me again 😉 I think I understand you now. I’ve see templates/custom_cms/template.php and found the the template code and need to change this in order to looks like my layout but what about with those controllers who don’t use CRUD? How I call this template to maintain the same layout across the site navigation?

  • #50 / Apr 25, 2011 10:52am

    web-johnny

    235 posts

    We talk about the same thing . You can change the template and add your own . If you want post your template and you will understand , its really really easy. you can either have many templates . For example : $this->output->set_template(‘my_custom_cms_2’); I have a documentation for this if you click here. The custom-cms is just an example. You can write your own template for instance :

    
    									
  • #51 / Apr 25, 2011 10:55am

    ReyPM

    86 posts

    This is what I’ve done now: changed the default template.php file and now look as follow:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html >
       <head>
          <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
          <title><?php echo ($title) ? $title : 'Sistema' ?></title>
          <link href="<?php echo base_url(); ?>assets/css/my_layout.css" rel="stylesheet" type="text/css" />
          <link href="<?php echo base_url(); ?>assets/css/basemod.css" rel="stylesheet" type="text/css" />
          <!--[if lte IE 7]>
          <link href="<?php echo base_url(); ?>assets/css/patches/patch_my_layout.css" rel="stylesheet" type="text/css" />
          <![endif]-->
          <?php foreach ($css as $file): ?>
             <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
          <?php endforeach; ?>
          [removed]var base_url = '<?= base_url() ?>';[removed]
          <?php foreach ($js as $file): ?>
             [removed][removed]
          <?php endforeach; ?>
       </head>
       <body>
          <div class="page_margins">
             <div class="page">
                <div id="header">
                   <div id="topnav">
                      <!-- start: skip link navigation -->
                      <a href="#navigation%22class=%22skip" title="skip link" class="skip">Skip to the navigation</a><span class="hideme">.</span>
                      <a href="#content%22class=%22skip" title="skip link" class="skip">Skip to the content</a><span class="hideme">.</span>
                      <!-- end: skip link navigation --><a href="#">Login</a> | <?php echo anchor('user/do_logout', isset($btn_logout) ? $btn_logout : 'Cerrar sesión'); ?>
                   </div>
                </div>
                <div id="nav">
                   <?php echo set_breadcrumb(); ?>
                </div>
                <div id="main">
                   <div id="col1">
                      <div id="col1_content" class="clearfix">
                         dsfsfsdfsdf
                      </div>
                   </div>
                   <div id="col3">
                      <div id="col3_content" class="clearfix">
                         <?php echo $output; ?>
                      </div>
                      <!-- IE Column Clearing -->
                      <div id="ie_clearing">   </div>
                   </div>
                </div>
                <!-- begin: #footer -->
                <div id="footer">Layout based on <a href="http://www.yaml.de/">YAML</a>
                </div>
             </div>
          </div>
       </body>
    </html>

    Now suposse that I have a static page where I don’t use any Grocery CRUD stuff because I want to show some text to users. Using this template.php modified file, how can achieve this? Before I only call $this->load->view() but now using CRUD isn’t clear.

  • #52 / Apr 25, 2011 10:55am

    web-johnny

    235 posts

    You have to this code to your template : (templates/frontend/custom-cms/template.php).

    Me again 😉 I think I understand you now. I’ve see templates/custom_cms/template.php and found the the template code and need to change this in order to looks like my layout but what about with those controllers who don’t use CRUD? How I call this template to maintain the same layout across the site navigation?

    The other code works like before . You will just need to put your template into your functions .You add a template IF you want . If not so the other code works fine 😊. You can do for example. :

    public function __construct() {
          parent::__construct();
          $this->load->add_package_path(APPPATH . 'third_party/grocery_crud/');
         
          $this->load->library('grocery_CRUD');
    }  
    public function index() {
     $this->output->set_template('custom_cms');
    
          if ($this->my_usession->logged_in) {
          $this->grocery_crud->set_table('trasegados')
                     ->set_subject('Trasegados')
                     ->columns('inicio_91', 'fin_91', 'total_91', 'inicio_95', 'fin_95', 'total_95', 'inicio_diesel', 'fin_diesel', 'total_diesel', 'id_estacion', 'usuario');
             $this->grocery_crud->fields('inicio_91', 'fin_91', 'total_91', 'inicio_95', 'fin_95', 'total_95', 'inicio_diesel', 'fin_diesel', 'total_diesel', 'id_estacion', 'usuario');
             $this->grocery_crud->required_fields('inicio_91', 'fin_91', 'total_91', 'inicio_95', 'fin_95', 'total_95', 'inicio_diesel', 'fin_diesel', 'total_diesel', 'id_estacion', 'usuario');
             $this->grocery_crud->render();
             $this->load->view('trasegados/form', $data);
          } else {
             redirect('user/login');
          }
       }  
    
    function my_test()
    {
        //This function will not have a template.
        $data = ...
        $this->load->view(...,$data);
    }
  • #53 / Apr 25, 2011 10:59am

    web-johnny

    235 posts

    The MY_output is designed only to work for crud . I didn’t find another way to add my javascripts and css . The other code works like before, with NO CHANGES at all. I hope this helps you and thank you for using grocery CRUD

  • #54 / Apr 25, 2011 11:03am

    ReyPM

    86 posts

    I’m lost again :( (what I’m idiot :( ) Let me expose what I’m understood:
    1. I add a template (/templates/custom_cms/template.php) if I want, right?
    2. If I don’t want to use this template then only use this code:

    $this->output->set_template('custom_cms');
     ... 
    $this->grocery_crud->render();
    $this->load->view('trasegados/form', $data);

    Right?
    3. If I don’t want to use Grocery CRUD and want to display a static page then this code should work:

    $this->load->view('trasegados/form', $data);

    If all this is right then I go back to my first post: when I try the second step I get the same errors as previous post so I’m totally lost.

    PS: Sorry for my english but my native language (write & read) is Spanish 😉

  • #55 / Apr 25, 2011 11:05am

    ReyPM

    86 posts

    The MY_output is designed only to work for crud . I didn’t find another way to add my javascripts and css . The other code works like before, with NO CHANGES at all. I hope this helps you and thank you for using grocery CRUD

    Don’t worry Grocery CRUD is amazing just need to understand how deal with it because if I do I’ll include in my upcoming projects 😊 this is for sure

  • #56 / Apr 25, 2011 11:16am

    web-johnny

    235 posts

    I’m lost again :( (what I’m idiot :( ) Let me expose what I’m understood:
    1. I add a template (/templates/custom_cms/template.php) if I want, right?
    2. If I don’t want to use this template then only use this code:

    $this->output->set_template('custom_cms');
     ... 
    $this->grocery_crud->render();
    $this->load->view('trasegados/form', $data);

    Right?
    3. If I don’t want to use Grocery CRUD and want to display a static page then this code should work:

    $this->load->view('trasegados/form', $data);

    If all this is right then I go back to my first post: when I try the second step I get the same errors as previous post so I’m totally lost.

    PS: Sorry for my english but my native language (write & read) is Spanish 😉

    Nooooooo. You are lost. Ok .
    1st of all - to work with grocery CRUD is REQUIRED to have a template. So in your functions you will have the $this->output->set_template(‘custom_cms’); line of code.

    So for example if you want to run my example you will do it like this:

    function my_boss_is_in_a_hurry()
    {
    //BUT you will not have this line to your contruct
        $this->output->set_template('custom_cms');
        
        $this->grocery_crud->set_table('customers');
        $this->grocery_crud->columns('customerName','phone','addressLine1','creditLimit');
     
        $this->grocery_crud->render();
    
        //AND you don't need the $this->load->view('trasegados/form', $data);
    }

    Now for your example. If you want to use ANOTHER function that don’t use the grocery CRUD . You will have it as before. So for example the Welcome page of codeigniter will be :

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Welcome extends CI_Controller {
    
        function __construct()
        {
            parent::__construct();
            $this->load->add_package_path(APPPATH . 'third_party/grocery_crud/');
             // $this->output->set_template('custom_cms');
              $this->load->library('grocery_CRUD');
    
        }
    
    public function index() {
        $this->output->set_template('custom_cms');
    
          if ($this->my_usession->logged_in) {
          $this->grocery_crud->set_table('trasegados')
                     ->set_subject('Trasegados')
                     ->columns('inicio_91', 'fin_91', 'total_91', 'inicio_95', 'fin_95', 'total_95', 'inicio_diesel', 'fin_diesel', 'total_diesel', 'id_estacion', 'usuario');
             $this->grocery_crud->fields('inicio_91', 'fin_91', 'total_91', 'inicio_95', 'fin_95', 'total_95', 'inicio_diesel', 'fin_diesel', 'total_diesel', 'id_estacion', 'usuario');
             $this->grocery_crud->required_fields('inicio_91', 'fin_91', 'total_91', 'inicio_95', 'fin_95', 'total_95', 'inicio_diesel', 'fin_diesel', 'total_diesel', 'id_estacion', 'usuario');
             $this->grocery_crud->render();
    
          } else {
             redirect('user/login');
          }
       }  
    
        function welcome()
        {
        //This is a full html page without template 
            $this->load->view('welcome_message');
        }
    
        
    }
    
    /* End of file welcome.php */
    /* Location: ./application/controllers/welcome.php */

    I think it’s easy you just don’t understand well the “template” thing . Perhaps is my fault because I didn’t documented very good.

  • #57 / Apr 25, 2011 11:23am

    ReyPM

    86 posts

    Ok I think I understood now 😊 Now I have another question. I have a class for encrypt/decrypt data when it’s inserted to DB. Which code I need to change in order to encrypt the data? I just call in my class as follow:

    $enc = new EncryptDecrypt();
    $cond = array(
              'usuario' => utf8_encode($enc->Encrypt($_POST['username'])),
              'pass' => utf8_encode($enc->Encrypt($_POST['password']))
    );
  • #58 / Apr 25, 2011 11:32am

    web-johnny

    235 posts

    Ok I think I understood now 😊 Now I have another question. I have a class for encrypt/decrypt data when it’s inserted to DB. Which code I need to change in order to encrypt the data? I just call in my class as follow:

    $enc = new EncryptDecrypt();
    $cond = array(
              'usuario' => utf8_encode($enc->Encrypt($_POST['username'])),
              'pass' => utf8_encode($enc->Encrypt($_POST['password']))
    );

    A simple one is php encrypt http://us2.php.net/manual/en/function.base64-encode.php dor encrypt and the base64-decode for decode(I can’t put two links in the forum). A good way to authorize a person is IonAuth

  • #59 / Apr 25, 2011 11:36am

    ReyPM

    86 posts

    Yes I know crypt PHP functions and this is not the problem. Maybe I asked in the wrong way: the question here is where the INSERT and UPDATES occurred in Grocery? Which files I need to edit to add support for encryption?

  • #60 / Apr 25, 2011 11:53am

    web-johnny

    235 posts

    Yes I know crypt PHP functions and this is not the problem. Maybe I asked in the wrong way: the question here is where the INSERT and UPDATES occurred in Grocery? Which files I need to edit to add support for encryption?

    You can use callbacks. All the callbacks you can see it from http://www.web-and-development.com/grocery_crud/crud/view/options_functions .

    for example : (please don’t just copy-paste the code because I didn’t tested . Perhaps I have wrong.) I Just want you to understand the “callback” logic.

    function example_2(){
        $this->grocery_crud->set_table('offices');
        $this->grocery_crud->set_subject('Office');
        $this->grocery_crud->required_fields('city');
        $this->grocery_crud->columns('city','usuario','pass','addressLine','postalCode');
    
        $this->grocery_crud->callback_before_insert(array($this,'code_encryption'));
        $this->grocery_crud->callback_before_update(array($this,'code_encryption')); 
        $this->grocery_crud->callback_edit_field('usuario',array($this,'username_decrypt'));
        $this->grocery_crud->callback_edit_field('pass',array($this,'password_decrypt'));
    
    
        $this->grocery_crud->render();
    }
     
    function code_encryption($post_array)
    {
        $enc = new EncryptDecrypt();
        $post_array['usuario'] = utf8_encode($enc->Encrypt($post_array['usuario']);
        $post_array['pass'] = utf8_encode($enc->Encrypt($post_array['pass']);
    
        return $post_array; // the post data that you return has been changed so the insert/update will be different :wink:
    }    
    
    function username_decrypt($value)
    {
        $enc = new EncryptDecrypt();
    $value = $enc->Decrypt($value);
        return '<input type="text" maxlength="50" value="'.$value.'" name="usuario" style="width:462px">';
    }
    
    function password_decrypt($value)
    {
        $enc = new EncryptDecrypt();
    $value = $enc->Decrypt($value);
        return '<input type="text" maxlength="50" value="'.$value.'" name="pass" style="width:462px">';
    }
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases