Why do I get Unable to include RenderObjectSuccess.php error when using inline in grid? - atk4

I'm setting up a grid with an inline field, pretty much the sames than in the examples in the demo, but I just keep getting error: Unable to include RenderObjectSuccess.php when chaning the value in the inline field. What a I doing wrong?
class page_alumnos_pago extends Page {
function init(){
parent::init();
$this->api->stickyGET('id');
$mAlumno=$this->add('Model_Alumno')->loadData($_GET['id']);
$g = $this->add('Grid');
$g->addColumn('date','fechaVencimiento');
$g->addColumn('text','concepto');
$g->addColumn('money','monto');
$g->addColumn('inline','temp_pago');
$g->setSource('programaPago');
$g->dq->where('alumno_id',$_GET['id']);
}
}
This is my ProgramaPago model:
class Model_ProgramaPago extends Model_Table {
public $entity_code='programaPago';
function init(){
parent::init();
$this->addField('alumno_id')->caption('Alumno')->refModel('Model_Alumno')->mandatory(true);
$this->addField('fechaVencimiento')->caption('Fecha de Vencimiento')->type('date')->mandatory(true);
$this->addField('monto')->caption('Monto')->type('money')->mandatory(true);
$this->addField('concepto')->caption('concepto')->type('text')->mandatory(true);
}
}

Eh, that's a bug.
https://github.com/atk4/atk4/issues/37
fix: https://github.com/atk4/atk4/commit/3694996
Please let me know if the fix works.

Related

Cakephp 2.9 passing a variable from Controller to Layouts View

The question i am asking is very similar and already asked question.But It is working for me.
ViewReportsController.php
class ViewReportsController extends AppController {
public function index() {
$count_table = 10;//sample variable that is available in view
$this->set('count_tablen',$count_table);
}
}
APP/View/Layouts/default.ctp
pr($count_tablen);
Now i am getting the error says- Undefined variable: count_tablen [APP/View/Layouts/default.ctp, line 228]
You are using a variable in your main layout template which is likely used by multiple controller actions. Therefore, the code example you've provided would only work on /view_reports/index. If you want to set variables to be used in the layout templates you need to do this in the beforeRender callback of AppController so that it can be used everywhere:-
public function beforeRender() {
parent::beforeRender();
$count_table = 10;
$this->set('count_tablen', $count_table);
}
If you use multiple layout templates you can check which template will be used in beforeRender before setting the variable:-
public function beforeRender() {
parent::beforeRender();
if ($this->layout === 'default') {
$count_table = 10;
$this->set('count_tablen', $count_table);
}
}

Extending class with no copying constructor (with private param)

During trying to enhance Angular's ComponetFixture I noticed that this can not be done because of no copying constructor for this class. (Or am I wrong?)
Let's suppose we have a class:
class A
{
constructor(public pub, private priv) { }
}
And I want to create class BetterA based on class A, so:
class BetterA extends A
{
constructor(a: A)
{
// super(a); <----- this can not be done, so maybe...
// super(a.pub, a.priv) // ...this could be better option, but...
}
myFunction(a: string) { return a; }
}
...second parameter is PRIVATE. I can not access it ;/
What can I do in that case?
I know that one of solutions is to use prototype like this:
A.prototype['myFunction'] = function(a: string) { return a; } // this must be done with function keyword, it's not working with ()=>{} !!! /there are problem with this pointer/
But then I have to write something weird like this:
console.log( classAobject['myFunction']("abc") );
Instead of
console.log( classAobject.myFunction("abc") );
or
I can do it by composition:
class B
{
public a: A; // or constructor(public a: A)
myFunction(a) { return a; }
}
But is seems not too elegant.
Is there any better solution?
Edit #1
I've just discovered that this syntax:
Class.prototype.NewFunction = function() { this.x.y.z = 123 }
is valid but it produces compiler errors, code works but we get:
'Property 'TextOf' does not exist on type 'Class'
and when you try to call it like this:
objectOfClass.NewFunction()
makes:
'Property 'NewFunction' does not exist on type 'Class'
BUT
It's gonna working only when we use function keyword. When we use lambda expression there will be same strange invisible problems with some functions.
I think composition is the way to go here. please remember that you are building a class and not a method which requires the new operator in order to instantiate your object. this may be what your looking for
class A{
tPub;
constructor(public pub, private priv) {
this.tPub=pub
}
}
class B extends A{
constructor(pub){
super(pub)
}
myFunc(){} //equiv to B.prototype.myFunc
}
export const myClass=new B();
//another file
import {myClass} from './file'
let m=myClass.myFunc();
unfortunately, by setting priv to private it will do exactly what it is told and make it a private object. you also could do without the constructor depending on what you would like to do with your class.

Cakephp 3 - reusable code for Table Entities

I have some code, that I need to apply for multiple Tables' Entities
similar to the example here
http://book.cakephp.org/3.0/en/orm/entities.html#accessors-mutators
protected function _setTitle($title)
{
// code to make re-usable
return $title;
}
Where can I move my code, so I can access it from multiple Entities. I tried a function inside Behavior, but it did not work.
Thanks
You can do this one of two ways. First, using a trait (a bit like what you were trying to achieve with a behavior):-
class Example extends Entity
{
use TitleTrait;
}
trait TitleTrait
{
protected function _setTitle($title)
{
return $title;
}
}
Second way is by using inheritance:-
class Example extends CustomEntity
{
}
abstract class CustomEntity extends Entity
{
protected function _setTitle($title)
{
return $title;
}
}

joining two models and show theme in one grid

I have two models:
A) Model ticket:
class Model_Ticket extends Model_Table {
public $table='ticket';
function init(){
parent::init();
$this->addField('subject');
$this->addField('content')->type("text");
}
}
B) Subticket:
class Model_Subticket extends Model_Table {
public $table='subticket';
function init(){
parent::init();
$this->addField('content')->type("text");
$this->addField('ticket_id')->type("int");
}
}
each ticket has many subtickets.
now I want to have a grid which the first row of that should be the "Content" of main ticket and other rows should be the "Content" of subtickets of that ticktet.
how can we do that?
thanks.
First create the grid which would display sub tickets, load them properly etc. Next look inside Grid's render() method. As you follow the execution, you'll find the following call chain:
grid::render()
CompleteLister::renderRows()
CompleteLister::renderDataRows()
You would need to override the normal rendering, fill out $this->current_row yourself and then call renderDataRows once before passing execution to parent::renderRows();
This will pop an extra row inside your Grid.

Adding fields on the fly

I have a form with a table source, the form has a few fields (product, quantity)
I'm thinking to add a button that allows me to add another "line" with product, quantity.... and so on, because I don't know how many items I need to add.
Which is the best approach ?
maybe removing the StaticSource('') and implementing on the submit the inserts ?
Thanks
Alejandro
class page_yourpage extends Page {
function init(){
parent::init();
$this->add("CRUD")->setModel("Product");
}
}
class Model_Product extends Model_Table {
$entity_code = "yourtable";
function init(){
parent::init();
$this->addField("product_id")->refModel("Model_Product");
$this->addField("quantity");
}
}
that's it. (did not test in browser);

Resources