T4MVC and DisplayModeProvider issue with fully qulified views - t4mvc

I have code that detects the user agent and creates a new display mode (ie. "tablet" and "mobile")
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("mobile")
{
ContextCondition = (context => GetDeviceType(context.GetOverriddenUserAgent()) == "mobile")
});
so when i want to return a view i just have to
return View("Index")
and the display mode will append "Index.tablet.cshtml" or "Index.mobile.cshtml" or nothing "Index.cshtml" for the default.
what is great about this is that if the user agent is "mobile" and there is no "Index.mobile.cshtml" file it will default to "Index.cshtml"
this works well but when using a fully qualified view name, as t4mvc does, "~/Views/Home/Index.cshtml"
the display mode logic does not add "tablet" or "mobile".
is there a way to have t4mvc return just "index" and not the fully qualified name?
or do you have another suggestion on how to resolve this issue and still use t4mvc?
thanks

Just choose return (MVC.YourController.Views.ViewNames.YourView)

Related

how to use the expand parameter in Xrm.WebApi.retrieveRecord

I am using below scripts to get the reference entity from email entity. When the scripts was triggered, it prompts 'Could not find a property named 'new_queue' on type 'Microsoft.Dynamics.CRM.email''.
The reference entity's scheme name is new_queue, and I think the structure of the script is same as the guidance of microsoft knowledge article.
(https://learn.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/retrieverecord)
Can anybody point out what's wrong here?
Xrm.WebApi.retrieveRecord("email", '4884f79f-42f3-ea11-a815-000d3a44afcc', "?$select=subject&$expand=new_queue($select=queueid,name)").then(
function success(result) {
var toLookup = new Array();
toLookup[0] = new Object();
toLookup[0].id = result.queueid;
toLookup[0].entityType = "queue";
toLookup[0].name = result.name;
alert(result.name);
}, function (error) {
Xrm.Utility.alertDialog(error.message);
});
This issue is usually an outcome of case sensitive schema name, try new_Queue instead of new_queue. You can always verify this by checking in xml metadata.
Update:
I remember that the activity (email, task, appointment, etc) is special and little different. Make sure you download the metadata xml from Developer resources and check the correct navigation property. It should look like email_new_queue or new_queue_email
To know the correct navigation property name to use it in $expand:
Request the "Email" entity and Include the following header Prefer: odata.include-annotations="*".
In the response, you should find a field that looks something like:
"_new_queue_value#Microsoft.Dynamics.CRM.associatednavigationproperty": "????"
Use the name you'll find in the place of "????" in the $expand expression.

How to render a cms page with default theme AND variables from controllers in OctoberCMS?

I'm wondering how I can render a view, or display a page with my default theme in OctoberCMS, via a route that executes a function in a controller.
If I have the following route:
Route::get('bransje', [
'uses' => 'Ekstremedia\Cityportal\CPController#bransje'
]);
And in my controller CPController ive tried several things, like I used to with Laravel:
public function bransje() {
$stuff = Stuff::with('info');
return View::make('cms::bransje')->with('stuff',$stuff);
}
But I cannot seem to get it to work, and I've tried to search the web, but it's hard to find answers. I have found a workaround, and that is to make a plugin component, then I can include that component and do:
public function onRun()
{
$this->eventen = $this->page['stuff'] = $this->stuff();
}
protected function stuff()
{
return ...
}
Is there any way so I can make pages without using the Cms, and that are wrapped in my default theme? I've tried
return View::make('my-theme-name::page');
and a lot of variants but no luck.
I know I can also do a:
==
public function onRun()
{
}
in the start of my page in the cms, but I'm not sure how to call a function from my plugin controller via there.
You can bypass frontend routing by using routes.php file in your plugin.
Full example in this video turotial.
If this answer can still be useful (Worked for October v434).
I have almost the same scenerio.
What I want to achieve is a type of routing like facebook page and profile.
facebook.com/myprofile is the same url structure as facebook.com/mypage
First I create a page in the CMS for each scenario (say catchpage.htm)
Then a created a catchall route at the buttom of routes.php in my plugin that will also not disturb the internal working of octobercms.
if (!Request::is('combine/*') && !Request::is('backend/*') && !Request::is('backend')) {
// Last fail over for looking up slug from the database
Route::get('{slug}/{slug2?}', function ($slug, $slug2 = null) {
//Pretend this are our routes and we can check them against the database
$routes = ["bola", "sade", "bisi", "ade", "tayo"];
if(in_array($slug, $routes)) {
$cmsController = new Cms\Classes\Controller;
return $cmsController->render("/catchpage", ['slug' => $slug]);
}
// Some fallback to 404
return Response::make(View::make('cms::404'), 404);
});
}
The if Request::is check is a list of all the resource that october uses under the hood, please dont remove the combine as it is the combiner route. Remove it and the style and script will not render. Also the backend is the url to the backend, make sure to supply the backend and the backend/*.
Finally don't forget to return Response::make(View::make('cms::404'), 404); if the resource is useless.
You may put all these in a controller though.
If anyone has a better workaround, please let us know.

Moodle theme change based on user type

I am using a Single Sign On technique from a Wordpress website,once the user logs on, they are automatically directed to the Moodle LMS namely 'courses/view.php?id=*relevant_id*'.
The $USER object already has the user type (called 'department' in this case) set up.
I want to do a theme switch based on this user type.
Something like:
if($USER->department == 'redTeam') {
$theme = 'RedteamTheme';
}
My question is:
Where would I place this code snippet?
Does anyone know the exact syntax?
I have looked around Google for hours and I cannot get the syntax
I have found how to do it in code.
In the lib folder you will need to amend 2 files:
pagelib and weblib. The pagelib file is a lengthy extension so I won't paste that code here. If anyone wants it, they can contact me, I will happily share.
the weblib needs to have this added to it for theme switching to work:
//create the function
function _setTheme(){
global $DB,$USER, $CFG, $THEME, $COURSE;//open abstraction layers
//set the criteria for te switch in this case I used the department field, it can also //be roles
$getRole = $USER->department;
if(!empty($getRole)) { //If the variable is not empty proceed with the switch
switch($getRole){
case 'role1':
$val = 'sky_high';
break;
case 'role2':
$val = 'leatherbound';
break;
}
} else {
//default theme
return 'leatherbound';
}
return $val;
}

Delete Action not working MVC 3

Route I have defined is:
map.Route(new Route("Cars/{id}/Delete",
new RouteValueDictionary(new { controller = "Car", action = "Delete"}),
new MvcRouteHandler()));
In my view I've got:
Delete
Which when run tries to send a request to http://oursite/Car/122/Delete
My delete action in this Car controller looks like this:
public ActionResult Delete(int id)
{
//code is here
}
I noticed a couple things:
If I run this same code locally via my PC, the delete works flawlessly and is able to get to my action method. I'm running this over IIS 7 / Win 7
On our dev server, it's setup obviously via IIS7 but this route fails and says it can't find the route on our route table. But this is the SAME route table class I am using locally...so why would I get this:
No route in the route table matches the supplied values.
But why would that not work on a dev server? I see the setup identical in IIS for the most part as far as I can see when I compare my local setup to the server's.
I noticed that also whether localhost or server, if I try and put an [HttpDelete] attribute on my delete action, it doesn't find my action method and I get an error saying it can't find that method. So not sure why when I take that off, the delete works (localhost only)
Use a helper to generate your link:
#Html.ActionLink("Delete", "Delete", "Car");
The first parameter is your link text, the second is your Action method name, and the third is your Controller name.
See this MSDN Reference on ActionLink().
Could you please share code for the View. How do you build the 'a' tag in the view?
Regarding the [HttpDelete] attribute, it means that the method needs the HTTP 'DELETE' request. The 'a' tag always has a GET request.
Please refer this link
I think you answered your own question. There is no route in the route table that matches your supplied values. You could write that route to do that by writing this in your Global.asax.cs file:
public class Global : System.Web.HttpApplication
{
protected void Application_Start()
{
// Specify routes
RouteTable.Routes.Add(new Route
{
Url = "[controller]/[id]/[action]",
Default = new { controller = "Car" },
RouterHandler = typeof(MvcRouteHandler)
});
}
}
Or, you can use existing routes (my personal recommendation) to use the Delete function in your Car controller. To do that, try switching your code to this:
Delete
First name that route
map.Route("DeleteCar",new Route("Cars/{id}/Delete",
new RouteValueDictionary(new { controller = "Car", action = "Delete"}),
new MvcRouteHandler()));
Then
Delete
Unless that link goes to a warning screen, I strongly suggest that a delete should be a POST or even a DELETE(I think it can be set via ajax)
There's likely a difference in the URL paths between localhost and oursite. The path "/Car/#Model.Id/Delete" is hard-coded, not resolved and may not work in all environments. As suggested in other answers, use an MVC helper like #Html.ActionLink or #Url.RouteUrl to resolve the path for the local environment.

joomla 1.5 multiple models, problem with default view

I'm developing a view that need to reuse a model, I'm following this documentation http://docs.joomla.org/Using_multiple_models_in_an_MVC_component. But that reference do the trick just (at least as far as I understand) when I use the parameter get task. if I use the view, joomla get me null data.
more clearly
controller.php - the task I named as the view I need
function viewdowhatIneed(){
$view = & $this->getView('viewdowhatIneed',html);
$view->setModel( $this->getModel( 'thenotdefaultmodelthatIneed' ), true );
$view->display();
}
model - thenotdefaultmodelthatIneed.php
class BLAModelthenotdefaultmodelthatIneed extends Jmodel{
function getReusableData0(){...}
function getReusableData1(){...}
}
view - view.html.php
class BLAViewviewdowhatIneed extends JView{
function display($tpl=null){
$dataneedit0 = $this->get('ReusableData0');
$dataneedit1 = $this->get('ReusableData1');
$this->assignRef('dataneedit0',$dataneedit0);
$this->assignRef('dataneedit1',$dataneedit1);
parent::display($tpl);
}
}
SO, what happen to me is:
example.com/index.php?option=com_BLA&view=viewdowhatIneed -> variables(datadataneedit0,dataneedit1) == NULL
example.com/index.php?option=com_BLA&task=viewdowhatIneed -> variables(datadataneedit0,dataneedit1) == Get me right data
then, my question is, is there a way to do the same thing, by using view parameter without task parameter (btw, I know this could be not a important problem, but I'm not an expert and on this reference http://docs.joomla.org/How_Joomla_pieces_work_together, it says:
The task part may or may not exist. Remember that if you omit it you are defaulting to task=display
so I really want to know that. In other words, can my view force to check the controller or vice versa.
Thanks in advance, excuse my english

Resources