Welcome Guest, Not a member yet? Register   Sign In
v 1.3.3 grocery CRUD - an automatic Codeigniter CRUD
#51

[eluser]ReyPM[/eluser]
This is what I've done now: changed the default template.php file and now look as follow:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
   &lt;head&gt;
      &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8" /&gt;
      &lt;title&gt;&lt;?php echo ($title) ? $title : 'Sistema' ?&gt;&lt;/title&gt;
      &lt;link href="&lt;?php echo base_url(); ?&gt;assets/css/my_layout.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="&lt;?php echo base_url(); ?&gt;assets/css/basemod.css" rel="stylesheet" type="text/css" /&gt;
      &lt;!--[if lte IE 7]>
      &lt;link href="&lt;?php echo base_url(); ?&gt;assets/css/patches/patch_my_layout.css" rel="stylesheet" type="text/css" /&gt;
      <![endif]--&gt;
      &lt;?php foreach ($css as $file): ?&gt;
         &lt;link type="text/css" rel="stylesheet" href="&lt;?php echo $file; ?&gt;" /&gt;
      &lt;?php endforeach; ?&gt;
      [removed]var base_url = '&lt;?= base_url() ?&gt;';[removed]
      &lt;?php foreach ($js as $file): ?&gt;
         [removed][removed]
      &lt;?php endforeach; ?&gt;
   &lt;/head&gt;
   &lt;body&gt;
      <div class="page_margins">
         <div class="page">
            <div id="header">
               <div id="topnav">
                  &lt;!-- start: skip link navigation --&gt;
                  <a class="skip" title="skip link" href="#navigation">Skip to the navigation</a><span class="hideme">.</span>
                  <a class="skip" title="skip link" href="#content">Skip to the content</a><span class="hideme">.</span>
                  &lt;!-- end: skip link navigation --&gt;<a href="#">Login</a> | &lt;?php echo anchor('user/do_logout', isset($btn_logout) ? $btn_logout : 'Cerrar sesi&oacute;n'); ?&gt;
               </div>
            </div>
            <div id="nav">
               &lt;?php echo set_breadcrumb(); ?&gt;
            </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">
                     &lt;?php echo $output; ?&gt;
                  </div>
                  &lt;!-- IE Column Clearing --&gt;
                  <div id="ie_clearing">   </div>
               </div>
            </div>
            &lt;!-- begin: #footer --&gt;
            <div id="footer">Layout based on <a href="http://www.yaml.de/">YAML</a>
            </div>
         </div>
      </div>
   &lt;/body&gt;
&lt;/html&gt;
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

[eluser]web-johnny[/eluser]
[quote author="ReyPM" date="1303757470"][quote author="web-johnny" date="1303756016"]You have to this code to your template : (templates/frontend/custom-cms/template.php).[/quote] Me again Wink 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?[/quote]

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. :
Code:
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

[eluser]web-johnny[/eluser]
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

[eluser]ReyPM[/eluser]
I'm lost again Sad (what I'm idiot Sad ) 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:
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:
Code:
$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 Wink
#55

[eluser]ReyPM[/eluser]
[quote author="web-johnny" date="1303757964"]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[/quote]
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 Smile this is for sure
#56

[eluser]web-johnny[/eluser]
[quote author="ReyPM" date="1303758227"]I'm lost again Sad (what I'm idiot Sad ) 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:
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:
Code:
$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 Wink[/quote]

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:

Code:
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 :
Code:
&lt;?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

[eluser]ReyPM[/eluser]
Ok I think I understood now Smile 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:
Code:
$enc = new EncryptDecrypt();
$cond = array(
          'usuario' => utf8_encode($enc->Encrypt($_POST['username'])),
          'pass' => utf8_encode($enc->Encrypt($_POST['password']))
);
#58

[eluser]web-johnny[/eluser]
[quote author="ReyPM" date="1303759397"]Ok I think I understood now Smile 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:
Code:
$enc = new EncryptDecrypt();
$cond = array(
          'usuario' => utf8_encode($enc->Encrypt($_POST['username'])),
          'pass' => utf8_encode($enc->Encrypt($_POST['password']))
);
[/quote]

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

[eluser]ReyPM[/eluser]
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

[eluser]web-johnny[/eluser]
[quote author="ReyPM" date="1303760217"]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?[/quote]

You can use callbacks. All the callbacks you can see it from http://www.web-and-development.com/groce..._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.
Code:
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 ;-)
}    

function username_decrypt($value)
{
    $enc = new EncryptDecrypt();
$value = $enc->Decrypt($value);
    return '&lt;input type="text" maxlength="50" value="'.$value.'" name="usuario" style="width:462px"&gt;';
}

function password_decrypt($value)
{
    $enc = new EncryptDecrypt();
$value = $enc->Decrypt($value);
    return '&lt;input type="text" maxlength="50" value="'.$value.'" name="pass" style="width:462px"&gt;';
}




Theme © iAndrew 2016 - Forum software by © MyBB