• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeExtinguisher 2.0 Release Candidate 14.2

[eluser]Donald Hughes[/eluser]
I apologize if I've missed it somewhere else, but I had a couple of questions.

1. Is there a way to add custom validation to a CRUD form? My specific issue is having a "from" and "to" date fields and I want to add validation to ensure that the "to" field is a later date than the "from" field.

2. What is the recommended method for doing something else after the record has successfully been inserted/updated?


Thank you very much for your help and for your excellent app.

[eluser]Majd Taby[/eluser]
1) Yes, look at the controllers/example.php file. It includes an example of a custom validation callback.

2) As the "temporary docs" outline, there are two ways to generate a page in CodeExtinguisher. Either using the CRUD controller (which automates basic tasks), or by writing your own controller (like the Example controller). If you use your own controller, then you can overload the execute_add or execute_edit functions to something like this:

IN YOUR CONTROLLER:
Code:
function execute_add(){
    CodexController::execute_add();
    /* DO SOMETHING HERE */
}

You can do this because in CodeExtinguisher, your controllers extend CodexController, not Controller, and execute_add/execute_edit do the inserting/updating.

[eluser]Donald Hughes[/eluser]
Thanks for the quick reply! So for adding custom validation callbacks, I just do it as I would for any CI form:

$rules['FIELD'] = "callback_FIELD_check";
...
function FIELD_check($str){}



One other question. What if I wanted to alter the data after the user submitted the request, but before the data is inserted/edited?

Thank you again!!!

[eluser]Majd Taby[/eluser]
you can add an event which gets called. Look at this thread for documentation on how to use Khaos::EventManager and this page for documentation on events that get triggered

[eluser]abmcr[/eluser]
A small fix in the plugin text_box:
Code:
$html .= '    <input class="text" type="text" value="'.stripslashes($this->value).'
adding stripslashes ifor not showiing the \

After
[quote author="jTaby" date="1212265104"]abmcr, In your field, you can add a "table_access_restriction" which does exactly that. http://codeextinguisher.pbwiki.com/Creat...-own-pages Smile[/quote]

I have try with this code
Code:
$config = array(
                    'db_table' => 'example', //The name of the table associated with this controller
                    'form_setup' => $this->spyc->YAMLLOAD($this->codexadmin->getDefinitionFileName('example_form')), //The array that holds our elements
                    'controller_name' => 'Example', //The name of the controller, so that it can be used when generating the URLs
                    'primary_key' => 'my_id', //The name of the controller, so that it can be used when generating the URLs
                    'display_fields'=>array('textbox_test','checkbox_test','related2'),
                    'order_by' => 'textbox_test',
                    'order_type' => 'ASC',
                    'table_access_restrictions '=>'textbox_test LIKE "r%"',
                    'rules'=>$rules
                    );
but nothing change....
And it is possible to set a restriction acces to the table on the related field?

My case is: i have a table "books" with
Code:
id, book....
After i have the table of the preview_chapter, with
Code:
id_chapter, description....
Finlay i have the books_preview_chapter table with a structure as
Code:
bk_cp_id,books_id,chapter_id
with the related data.

I want to display a view with a selec as
Code:
SELECT preview_chapter.*
FROM preview_chapter
INNER JOIN books_preview_chapter ON preview_chapter.id_chapter= books_preview_chapter.chapter_id
WHERE books_preview_chapter.books_id= 5567

And, yet, it is possible to get dinamyc the id, using a uri_segment?
My idea was a code as
Code:
$config = array(
                    'db_table' => 'preview_chapter', //The name of the table associated with this controller
                    'form_setup' => $this->spyc->YAMLLOAD($this->codexadmin->getDefinitionFileName('example_form')), //The array that holds our elements
                    'controller_name' => 'Example', //The name of the controller, so that it can be used when generating the URLs
                    'primary_key' => 'id_chapter', //The name of the controller, so that it can be used when generating the URLs
                    'display_fields'=>array('description','pdf','books_preview_chapter'),
                    'order_by' => 'textbox_test',
                    'order_type' => 'ASC',
                    'table_access_restrictions '=>'books_preview_chapter LIKE "'.$this->uri->segment(4)."',
                    'rules'=>$rules
                    );

There is a more simple way to get this goal?

[eluser]Majd Taby[/eluser]
yes, but table_access_restrictions takes an associative array, and it passes the Key as the first parameter, and the value as the second parameter to $this->db->where

[eluser]abmcr[/eluser]
Code:
$config = array(
                    'db_table' => 'example', //The name of the table associated with this controller
                    'form_setup' => $this->spyc->YAMLLOAD($this->codexadmin->getDefinitionFileName('example_form')), //The array that holds our elements
                    'controller_name' => 'Example', //The name of the controller, so that it can be used when generating the URLs
                    'primary_key' => 'my_id', //The name of the controller, so that it can be used when generating the URLs
                    'display_fields'=>array('textbox_test','checkbox_test','related2'),
                    'order_by' => 'textbox_test',
                    'order_type' => 'DESC',
                    'table_access_restrictions '=>array('textbox_test LIKE '=>"aaa %"),
                    'rules'=>$rules
                    );
        $this->setConfig($config);
but any restriction are applied :down:

[eluser]Majd Taby[/eluser]
abmcr, here are lines 244->246 of codexcontroller.php:

Code:
if(count($this->table_access_restriction) > 0)
            foreach($this->table_access_restriction as $field=>$value)
                $this->db->where($field,$value);

As far as your query not working, I would suggest adding an "echo $this->db->last_query()" to see what is being applied and what isn't.

[eluser]Donald Hughes[/eluser]
For custom validation I get a
"Message: Undefined property: News::$validation"

When I try to use
"$this->validation->set_message()".


How do I set a custom error message? Thanks again!

[eluser]Donald Hughes[/eluser]
I figured it out. Just changed “$this->validation->set_message()”. to “$this->codexvalidation->set_message()”.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.