CakePHP pagination with custom method - cakephp

I need to implement a custom pagination where one of the fields needs to be populated by a custom PHP method that cannot be implemented using MySQL - ie, I cannot rely on virtualFields.
I tried to use a custom find type, capturing the after event and populating the custom field but the pagination doesn't work with this custom property.
In practical terms, this is what I do to do:
$readers = $this->Paginator->paginate('Reader', array(
'Reader.account_id' => $this->Auth->user('user_id')
));
$readers would have a status property where it's populated using a PHP method. How can I use this dynamic property and the Pagination component at the same time?

Please use these lines
$this->paginate=array('conditions'=> array('Reader.account_id' => $this->Auth->user('user_id')));
$readers=$this->paginate('Reader');

Related

Form.io AngularJS Setting 'options'

I am using form.io (angular JS) to create a form using a JSON object. Also using the 'wizard' mode.
This works well, but i just cant seem to understand how to set the options for the form.
Specifically the breadcrumbSettings.clickable setting, which i need to set to false.
I am creating the form in the HTML like this:
<formio form="formCtrl.formio" submission="submission" ></formio>
I tried setting the 'options' param in the html/JS/accessing the form object. Nothing works.
And i cant find a relevant example for setting the options object using angular js.
Anyone out there knows how to achieve this?
Thanks,
Guy
As per the documentation you have to pass formio-options attribute to the above formtag.
Documentation link: https://github.com/formio/ngFormio/wiki/Formio-Directive
example: <formio src="currentForm" formio-options="{skipQueue: true}"></formio>
You would have to pass json of options applicable to formio here in formio tag.
Here some more link from documentation from official repository: https://github.com/formio/help.form.io/blob/49f570dab40edc87234cc06f4dd833aa7aa03561/_paragraphs/developer/offline/offlineapi.md#request-options

How to use $http.get for populating ng-admin choice field?

How would/can you populate a ng-admin "choice" field using angular $http.get method call?
Something like this would pull a list of companies from the '/companies' endpoint and populate the select field with it. It will also highlight the currently selected company. It won't be a "choice" kind of field.
nga.field('company.id', 'reference')
.label('Company')
.targetEntity(admin.getEntity('companies'))
.targetField(nga.field('name'))
.validation({required: true }),
You can try creating a custom directive, but you'll have to dig through the ng-admin internals to make sure you work with their API. And then you'll have to pray they don't change that api. Custom directives are easier to think about and manage if you're saving one field at a time and not filling out a huge form. But if you're saving one field at a time, you'll operating outside of ng-admin and if you do enough of those tricks, then you won't need ng-admin other than for basic listings and pagination.
You're probably looking for the 'reference' field (see documentation). If this doesn't fit your need, you'll have to use a custom directive using ui-select (already used by ng-admin) and a custom Restangular call.
Pointers:
ng-admin's ma-choice-field directive
a directive making custom HTTP calls on ng-admin-demo

ExtJS ref to panel element with specific title

I am working on a project in ExtJS 4.2 written in the MVC pattern. I need a reference to a specific item inside MyViewport (extended from the class Ext.container.Viewport). The item which needs to be referenced from within the controller has the Class MyPanel (extended from "Ext.Panel"). Problem is there are several items with the same class, so simply doing a standart ExtJs-component-query like,
//inside myController.js
refs: [
...
{ref: 'specificItem', selector: 'MyViewport_alias > myPanel_alias'},
...
]
wont get me a reference to the item. Thats why i thought of retrieving the reference by something like this, since the items using MyPanel-class have a property title:
//inside myController.js
refs: [
...
{ref: 'specificItem',
selector: 'MyViewport_alias > myPanel_alias > title="title of specific item"'},
...
]
But i coulnd't find any examples on retrieving items as references by using their properties as parts of the component query other than this.
Has someone experience with this kind of problem?
Component queries in ExtJS are very similar to CSS query selectors. You could find a component by a specific property with syntax similar to: "... > [title=My Component Title]" - that said, using the "title" sounds like really bad practice.
At worst, as a visible part of the user-interface it's very sensitive to change - easily breaking your application and at best it immediately limits your application's language-support and configurability.
Ideally you should be utilising the itemId property as a more robust way of referencing components.
» fiddle
I hadn't noticed that 4.2 didn't support attribute selectors - the component query functionality seems to have always drawn inspiration from CSS though, so unfortunately if it's only a recent development it doesn't look like there's any way to do what you want using this method.
You'd have to manually fetch the component and/or create your own reference. You can select by xtype / alias in 4.2 and then apply a filter to the result, for example:
Ext.Array.filter(Ext.ComponentQuery.query('panel'), function(x){
return !!x.title.match('Sub Panel 2');
}).shift();
( Obviously no use in a controller's refs )
» fiddle
... this is however ugly - all the more reason to use itemId's properly. There was already an example of this in action in the first fiddle. All you need to do is assign an alphanumeric string (no spaces) to the property - these don't strictly need to be unique but it's generally preferable. Then in your selector simply prefix a hash # in front of the string which indicates to the engine that you are looking for a component with a specific ID.
itemId selectors definitely work in 4.2 so without seeing your code I can only speculate as to what the problem is. In your post you are using > which narrows the query to direct descendants only. Are you absolutely sure that the component you are looking for is a child of myPanel_alias and not wrapped up in another container? i.e.
"myPanel_alias #myItemId" <-- try this
"myPanel_alias > #myItemId" <-- instead of this

Cakephp2 pagination with GET parameters

I have a list page with a filter form and Im submitting the form using get method. How to pass the querystring parameters along with the pagination links. I have checked this link
CakePHP pagination and the get parameters but this->passedArgs is coming as empty. Im using cakephp2. Whats the best option to solve this ?
This is some code I use in a CakePHP 1.3 project. I believe it should still work on CakePHP 2.0 as well (put this in the view where your filter form is):
// Make sure we pass any set filters to the Paginator helper
$urlParams = $this->params['url'];
unset($urlParams['url']);
$this->Paginator->options(array('url' => array('?' => http_build_query($urlParams))));

How Do I Filters the list by refModel('Model_user') in the Models?

I am unable to find how to filter the drown down which i got by using refmodel in my model which extends model_table
thanks in advance
For any view in toolkit you can use setController and getController. refModel fields from Model will set a proper controller for a form field. It uses type reference.
Once form in initialized, you can interact with controller of a field by
$field->getField('myfield')->getController()->addCondition('type','admin');
Alternatively the following might work too:
$field->getField('myfield')->dictionary()->addCondition('type','admin');

Resources