Can I ask Nancy if a view exists? - nancy

In my nancy project I have views which are based on a 4-digit numeric id, as in 1234.cshtml, 2345.cshtml et cetera. Not all 10000 values exist, and if an id is requested for which there is not a view, I want to redirect to another page.
In my routing code how can I test if, for example, view 5432.cshtml exists? is there a helper method in Nancy for this? Or should I just query the file system?

inject IViewLocator and use LocateView method to test if the view exists.

Related

CakePHP 3 - How to identify the installed behaviors in a model when baking a controller

I'd like to adapt my controller baking code (vendor/cakephp/bake/src/Template/Bake/Template/Bake/Controller/controller.ctp) so when baking a controller it will automatically detect if there is a (f.e. Translate-) behavior installed in the model and add "use Cake\I18n\I18n;" to the controller while baking it.
So, can anyone tell me how to identify the installed behaviors within the controller-baking-code?
Given that the table class already exists when baking the controller, you should be able to get the required information from $modelObj that is passed to the view, it's an instance of the table class that is associated with the controller.
The behavior registry available via Table::behaviors() should have the info that you need.
$modelObj->behaviors()->has('Translate')
And of course you can get further information from the table, like the schema (Table::schema()), validation rules (Table::validator()), etc...
See also
API > \Cake\ORM\Table::behaviors()
API > \Cake\ORM\BehaviorRegistry::has()

Show Opportunity related Contacts in Custom Object Field

I have the next issue.
I have a custom object called 'Application', and I have this requirement:
"Show all Contacts related to an Application. Create a field on Application object, must be read only".
I solve it with apex code. 'Application' has a lookup to Opportunity, Opportunity to Account, and all my contacts have AccountId, so this way, I get all the contacts using apex code in a trigger.
But, I've been ask to change this to a Formula field in Application object.
So, my issue is next. I'm not able to get all contacts with advance formula editor, because they're not part of any object. I have no master-detail relationship.
Does any one know how can I achieve this using configuration? I should not use apex code for this req.
Thank in advance guys.
I don't think you can do it.
In formulas / merge fields syntax there's no way to go "up, up then down" (Application -> Opportunity -> Account -> down to Contacts related list). There's also nothing that would let you loop through Contacts (and display what? Ids? Names? Emails?). Roughly speaking you can only go up through dots.
You might want to explore path of "cross object workflow" rules but I imagine that when I add a new Contact to Account it should somehow "spread itself" to all related Applications? There's no straight way to fire a workflow on delete too - so you'd eventually end up with inaccurate list.
I'd say trigger was a good solution. Maybe it ws unoptimized but if it has to be in a field - tough.
There might be a fairly simple way of achieving that by embedding a visualforce page within Application page layout.
This should be doable with pure Visualforce (so technically there will be no Apex code ;))
Something as simple as
<apex:relatedList list="Contacts" subject="Application__c.Opportunity__r.AccountId" />
would be a good start (if you want your own layout and not a rel. list - you should be still able to pull it off with <apex:repeat> or <apex:pageBlockTable>.
There's one BUT here: it's not a field, just a display trick. Forget about using it in reports, mobile applications etc.
Another way - would it be acceptable to be 1 click away from these contacts? You could make a report "Account with Contacts", filter it by Id of one Account and later use "URL hacking" to change the filter depending on from which Application you'll click it. This link could be either a formula field or a real custom button/link. Technically - it's pure config, no apex & VF.
You can read more about URL hacking at Ray Dehler's excellent post and specifically about dynamic Reports here or here.

Pyrocms Getting Values at front end

I am new to pyrocms.
How can I get database values on pages of pyrocms. In website of pyrocms I had created a listing page now I want to display database values from pyro database table.
I got your question, you want to create a listing on your front-end page for some database table values which you want to access through your custom module controller. there are many ways to get these values but the simplest way is to use ajax. you already have Jquery added in pyrocms so you can simply make a call to your controller method in ajax and get your required output as HTML and display it in the div element on your page.
$.ajax({
type:"POST",
url:"admin/your-controller-name/your-method-name",
success:function(html){
$('yourdiv').html(html);
}
})
In your controller create a method which get data from database and print it using echo create some listing table etc what you want.
i think you will get my point. if confuse then get back to me
You need to be more specific as PyroCMS has lots of components and each module (blogs, variables, widgets, file uploads etc.) uses specific tags you insert into the page. You may come across references to 'Lex' - that's the name of the parser used to display them.
Tags documentation
PyroCMS (the Professional edition) also has a feature called "Streams" which allows you to build custom databases and this in turn has it's own series of tags.

Output User firstname lastname as link to profile in Drupal 7 views

In Drupal 7, I'm trying to output a list of users related to a node in a view, which I've got working fine.
However, the only way to link to the user profile is to use the user:name field in views, which gives me the markup
username.
I've got two additional profile fields, user:Firstname and user:Lastname, but can't see to find a way to do this:
[user:firstname] [user:lastname]
as each time I try and rewrite the output of the link, it refuses to work; user:url doesn't exist as option in my views UI (which contains the link I need according to Devel).
Thoughts?
I've not used it. But my educated guess is that the easiest solution for you would be to look at the realname module, which should do all the heavy lifting for you.

two independent dropdowns with xml binded data - cakephp - best method?

What's best method within cakephp site for-
two dropdowns
one listing cds, one listing artists
on select of either cd or artist I need my additional text to appear below dropdowns
I have been searching through tutorials and manual - with no success. I am looking to learn by basic example - from form/view and controller.
latest try was something along this example to get dropdown [Dropdown select list in CakePHP
Although CakePHP techniques apply, the way that I'd do this in CakePHP is the same way I'd do it in any app. I'd use Javascript (the jQuery framework in my case) to:
Bind an event handler to the change event of each dropdown
Make an Ajax call to a URI that returns the "additional text" to be displayed below the dropdown
Display said text
In the CakePHP context, I'd create methods in my CdsController and ArtistsController (I'm guessing at your naming convention, of course) to respond to the Ajax request.

Resources