假设我有一个控制器,"文章",但我希望它显示为子文件夹(例如"博客/文章"),我可以添加这样的路线:
$route['blog/articles'] = 'articles';
$route['blog/articles/(:any)'] = 'articles/$1';
Run Code Online (Sandbox Code Playgroud)
这工作正常,现在唯一的问题是,example.com/articles并且example.com/blog/articles都使用Articles控制器,因此解析为相同的内容.有办法防止这种情况吗?
为了让人们不理解,可以增加一点清晰度:
example.com/articles返回404,因为那不是正确的URL,example.com/blog/articles是.在控制器中创建标准后,我不知道如何创建特定字段的运行总和
我正在使用以下方法创建一组记录:
def b = Tapes.createCriteria()
def yesterday = b.list(sort: 'migratedDate', order: 'asc') {
between ("migratedDate", dat.minus(1), dat)
}
Run Code Online (Sandbox Code Playgroud)
并计算该组中的项目数
def num2 = Tapes.countByMigratedDateBetween(dat.minus(1), dat)
Run Code Online (Sandbox Code Playgroud)
我的域中的一个字段是"migratedDuration",系统以毫秒为单位返回进程的运行时.在控制器中有一种方法可以创建这个数字的总和吗?或者我应该在相应的.gsp文件中通过javascript执行此操作吗?
再次感谢,
一个可怕的糟糕黑客
这非常有效,谢谢
def todayTime = aa.list() {
between ("migratedDate", dat.minus(4), dat.minus(3))
projections { sum('migratedDuration')
}
}
Run Code Online (Sandbox Code Playgroud) 我想在执行每个控制器的方法之前调用一个方法.我不想在每种方法中调用该方法.我只是想从一个地方调用它,它将在magento中任何控制器的任何方法之前调用.
我相信我们可以做到这一点,但我不知道如何实现.
请提供您的建议.
希望我们能解决这个问题,或者一些专家已经解决了这个问题.
谢谢.
我有一个不能被直接访问,在传统的RESTful方式的控制,而只能通过特定的URL.
通常我已经习惯了使用GET和POST在我的控制器的规格调用控制器动作.有没有办法通过访问特定网址来运用我的控制器?
编辑:
这是我的路线:
Larzworld::Application.routes.draw do
match '/auth/:provider/callback' => 'authentications#create'
devise_for :users, :controllers => {:registrations => "registrations"}
root :to => 'pages#home'
end
Run Code Online (Sandbox Code Playgroud)
这是我的规格:
require 'spec_helper'
describe AuthenticationsController do
before(:each) do
request.env["omniauth.auth"] = {"provider" => "twitter", "uid" => "12345678"}
end
describe 'POST create' do
it "should find the Authentication using the uid and provider from omniauth" do
Authentication.should_receive(:find_by_provider_and_uid)
post 'auth/twitter/callback'
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我收到的错误:
Failures:
1) AuthenticationsController POST create should find the Authentication using the uid and provider from omniauth
Failure/Error: …Run Code Online (Sandbox Code Playgroud) 我是CodeIgniter的新手,但我想我已经掌握了它的工作原理.
通常,当我创建一个网站,比如一个5页的网站时,我将我的头文件放在每个页面中包含的php文件中,这样如果我必须改变标题,我只需要在一个地方而不是改变它五次.
在我的CodeIgniter应用程序中,我的控制器中的每个页面都有一个函数,它根据函数加载不同的视图.例如,
public function Index() {
$data = array();
$this->load->view('index',$data);
}
public function blog() {
$data = array();
$this->load->view('inner1',$data);
}
Run Code Online (Sandbox Code Playgroud)
然后我可以将所有逻辑放在控制器中.
有一个引用标题的最佳方法是什么?我应该将它作为变量放在控制器中,然后将其作为数据发送到每个视图吗?
此外,如果有更有效的方法,请建议!
谢谢!
我在我的magento 1.7商店安装了扩展CreativeStyle CheckoutByAmazon,我试图覆盖CheckoutController类但是magento似乎忽略了我的覆盖.任何建议将不胜感激.还清除缓存但仍然无法正常工作
(在app/code/local文件夹中)
MyModule\CheckoutByAmazon\controllers\CheckoutController.php\etc\config.xml
(应用程序的/ etc/config.xml中)
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyModule_CheckoutByAmazon>
<version>0.1.0</version>
</MyModule_CheckoutByAmazon>
</modules>
<frontend>
<routers>
<checkoutbyamazon>
<args>
<modules>
<MyModule_CheckoutByAmazon before="Creativestyle_CheckoutByAmazon">MyModule_CheckoutByAmazon</MyModule_CheckoutByAmazon>
</modules>
</args>
</checkoutbyamazon>
</routers>
</frontend>
</config>
Run Code Online (Sandbox Code Playgroud)
(在app/code/local/MyModule/CheckoutByAmazon/controllers/CheckoutController中)
<?php
//Controllers are not autoloaded so we will have to do it manually:
require_once 'Creativestyle/CheckoutByAmazon/controllers/CheckoutController.php';
class MyModule_CheckoutByAmazon_CheckoutController extends Creativestyle_CheckoutByAmazon_CheckoutController {
public function indexAction() {
exit('I am here');
parent::indexAction();
}
//i want to override this function
public function saveShippingAction() {
//insert my overriding code
exit('saveShipping');
}
}
?>
Run Code Online (Sandbox Code Playgroud)
(在etc/modules/MyModule_CheckoutByAmazon.xml中)
<?xml version="1.0"?> …Run Code Online (Sandbox Code Playgroud) 当我在View Alternate中时,我知道我可以通过以下方式获取ContentItem的显示URL:
@Url.ItemDisplayUrl(contentItem)
但是当我在控制器上下文(ActionResult)时,我不知道如何获取显示URL.出于站点地图的目的,我需要列出的ContentItems的URL.
我正在使用下面的代码.
public class SiteMapResult : ActionResult
{
readonly IContentManager _contentManager;
readonly ITagService _tagService;
public SiteMapXmlResult(IContentManager contentManager, ITagService tagService)
{
_contentManager = contentManager;
_tagService = tagService;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml";
string host = context.HttpContext.Request.Url.Host;
StringBuilder xml = new StringBuilder();
xml.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
xml.Append(@"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">");
var contentItems = _contentManager.Query(VersionOptions.Latest, GetContentTypeNames().ToArray()).List();
foreach (var contentItem in contentItems)
{
// The display url of contentItem
}
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何获取ContentItem显示URL?
我试图将我的整个类包含控制器添加到我的指令中,因为一些显而易见的原因,范围和语法不正确.我使用typescript作为语言和grunt-ts进行自动生成和编译.
/// <reference path="../reference.ts" />
directives.directive('myDirective', function ():ng.IDirective {
return {
restrict: 'EAC',
template: directiveHTML.html, \\ thanks to grunt-ts this work fine
controller: MyControllerClass, \\ here I get the error and here I would like to
put my own controller class instead of a function
link: function (scope, elements, attrs) {
}
}
Run Code Online (Sandbox Code Playgroud)
});
在这里我的控制器的类
module Controllers {
export class CursorController {
constructor($scope, socket){
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后将所有控制器添加到angularJS的控制器模块中(引用由grunt-td自动生成).
/// <reference path="../reference.ts" />
angular.module('controllers',[]).controller(Controllers);
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何线索或建议都会很棒.
我是Laravel的新手,我不确定我知道自己在做什么.我在主视图中有一个表单.我将输入传递给控制器,我希望数据显示在另一个视图中.我似乎无法从控制器到第二个视图获取数组.我一直得到500 hphp_invoke.这是我将数组从控制器传递到view2的地方.
public function formSubmit()
{
if (Input::post())
{
$name = Input::get('name');
$age = Input::get('age');
$things = array($name, $age);
return View::make('view2', array('things'=>$things));
}
}
Run Code Online (Sandbox Code Playgroud)
view1.blade.php
{{ Form::open(array('action' => 'controller@formSubmit')) }}
<p>{{ Form::label('Name') }}
{{ $name = Form::text('name') }}</p>
<p>{{ Form::label('Age') }}
{{ $age = Form::text('age') }}</p>
<p>{{ Form::submit('Submit') }}</p>
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)
我的view2.php文件非常简单.
<?php
echo $name;
echo $age;
?>
Run Code Online (Sandbox Code Playgroud)
然后在routes.php中
Route::get('/', function()
{
return View::make('view1');
});
Route::post('view2', 'controller@formSubmit');
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?
我已经阅读了许多关于允许不同的视图按钮使用不同的控制器动作的文章。但是,我无法使它正常工作。
我使用从http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/获得的代码段。
public class HttpParamActionAttribute : ActionNameSelectorAttribute
{
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
return true;
if (!actionName.Equals("Action", StringComparison.InvariantCultureIgnoreCase))
return false;
var request = controllerContext.RequestContext.HttpContext.Request;
return request[methodInfo.Name] != null;
}
}
Run Code Online (Sandbox Code Playgroud)
当我通过这个代码一步,我看到一个比较actionName有methodInfo.Name。当整个目的是要命名与控制器动作不同的方法时,这些EVER怎么相等。
对于行为/功能,true或false的返回值实际上意味着什么?
我是否应该将“ fciContactUs”操作替换为“ Action”?
控制器=“ HomeController”
[HttpParamAction]
[ActionName("Action")]
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public ActionResult DoClearForm(fciContactUs p_oRecord)
{
return RedirectToAction("fciContactUs");
}
[HttpParamAction]
[ActionName("Action")]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult TrySubmit(fciContactUs p_oRecord)
{
// This must be the Submit command.
if (ModelState.IsValid) …Run Code Online (Sandbox Code Playgroud) controller ×10
view ×3
codeigniter ×2
magento ×2
angularjs ×1
arrays ×1
button ×1
events ×1
grails ×1
gruntjs ×1
hibernate ×1
javascript ×1
laravel ×1
orchardcms ×1
overriding ×1
php ×1
razor ×1
routes ×1
routing ×1
rspec ×1
sitemap ×1
typescript ×1
url ×1