我有一个管理控制器位于controllers/admin/admin_controller.rb
我还有一个页面控制器位于
routes.rb controllers/admin/pages_controller.rb
pages_controller.rb继承admin_controller.rb,我有一个管理命名空间,如下所示:
map.namespace :admin do |admin|
admin.resources :pages
end
Run Code Online (Sandbox Code Playgroud)
pages_controller.rb(我知道该怎么做)index和show方法可供前端用户使用问题:
pages_controller的前端,或共享的方式index和show?/admin/pages或/pagespages_controller在/controllers/admin(它是现在),或者只是/controllers?非常感谢你.
我在我的控制器中有这个:
[HttpPost]
public void UpdateLanguagePreference(string languageTag)
{
if (string.IsNullOrEmpty(languageTag))
{
throw new ArgumentNullException("languageTag");
}
...
}
Run Code Online (Sandbox Code Playgroud)
并将此jQuery代码POST到控制器:
jQuery.ajax({
type: 'POST',
url: '/Config/UpdateLanguagePreference',
contentType: 'application/json; charset=utf-8',
data: '{ "languageTag": "' + selectedLanguage + '" }'
});
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试代码时,我收到错误:
Server Error in '/' Application.
Value cannot be null.
Parameter name: languageTag
Run Code Online (Sandbox Code Playgroud)
有什么问题?这不是如何将JSON POST到MVC控制器?我可以使用Fiddler检查POST,看看请求是否正确.出于某种原因,UpdateLanguagePreference()获取null或空字符串.
我刚开始使用cakePHP,到目前为止情况还不顺利.
我有一个控制器来处理确认用户的电子邮件.在注册时,用户将在链接中收到带有确认码的电子邮件.根据它们给出的确认代码,控制器会给出不同的文本响应.其中一个响应包括一个超链接以便登录.
我正在尝试使用Html助手,但是虽然我已经将它加载到类顶部的$ helpers中,但是如果我然后使用App :: import然后实例化它,我只能使它工作.
简单地制作一个超链接似乎有点过分了!我有多少次加载同一个类?
无论我在网上看哪,它一直告诉我在控制器中使用帮助器是个坏主意,但我还应该如何获得链接呢?
所以我有
var $helpers = array('Html');
Run Code Online (Sandbox Code Playgroud)
在控制器的顶部,并:
if (isset($this->User->id)) { // Check the user's entered it right
// Do some stuff to remember the user has confirmed
// This is to load the html helper - supposedly bad form, but how else do I make the link?
App::import('Helper', 'Html');
$html = new HtmlHelper();
$this->set('message', __("Your email address has been confirmed.", TRUE)." ".$html->link(__("Please log in", TRUE), array('controller' => "users", 'action' => "login" )));
} …Run Code Online (Sandbox Code Playgroud) 如何在没有grails尝试生成视图的情况下调用我的某个控制器类中的方法?
我有一个列出一堆类别的视图:
<ul>
<li>@Html.ActionLink("All", "Index", "Products")</li>
@foreach (var item in Model.ProductCategories)
{
<li>@Html.ActionLink(item.Name, "Index", new { id = item.Id }, null)</li>
}
</ul>
Run Code Online (Sandbox Code Playgroud)
如图所示,我应该得到一个类别链接列表,最上面的一个是"All",下面的是相应的类别名称,id传递给控制器.
我的控制器看起来像这样:
public ActionResult Index(int? id)
{
var categories = _productCategoryRepository.GetAll().OrderByDescending(f => f.Name);
var items = id == null
? _productItemRepository.GetAll().OrderBy(f => f.Name).ToList()
: _productCategoryRepository.GetSingle((int)id).ProductItems.OrderBy(f => f.Name).ToList();
var model = new ProductsViewModel()
{
ProductCategories = categories,
ProductItems = items
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
所以类别应该始终相同.但是,项目应显示出每一个项目,当ID是空当该特定类别的物品ID设置.
这一切都非常好,所以当我点击一个类别链接.我这样得到了网址:
/产品/首页/ 3
大!现在我点击"全部"链接,但它将我路由到/ Products/Index/3,即使我显然没有传递参数.我尝试传递一个空值:
@Html.ActionLink("Alle", …Run Code Online (Sandbox Code Playgroud) 我试图从URL捕获一个通配符,然后首先将其传递给过滤器,然后路由到控制器.我不确定如何准确地绘制问题,但这是我到目前为止所尝试的内容.
Route::get('test/(:any?)', array('as' => 'testroute', 'uses' => 'test@result', 'before' => "test_filter:$1"));
Route::filter('test_filter', function($id = NULL)
{
if($id)
echo "This id is " . $id; // Prints "This id is $1"
});
Run Code Online (Sandbox Code Playgroud)
和
Route::get('test/(:any?)', array('as' => 'testroute', function($id = NULL)
{
if($id)
echo "this id is " . $id; // Does not do anything
}, 'uses' => 'test@result'));
Run Code Online (Sandbox Code Playgroud)
基本上,我想检查是否有一个id附加到URL并设置一个cookie(如果有的话).但无论如何,我都希望这个路由由控制器处理,无论是否附加了任何id.
我必须用这么多路径做同样的事情,所以我更喜欢像过滤器这样的东西,而不是修改控制器的代码.
我知道我可以直接将通配符元素传递给闭包,或者我可以将它作为参数提供给任何控制器,但在这种情况下我将不得不修改控制器代码,这是我目前无法做到的.
我可以通过过滤器吗?或者我不需要修改控制器代码的任何其他方式?
每当我想在mininet或某些客户代码中运行sshd.py示例时,我就自己写了
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 h3 h4 h5
*** Adding switches:
s1
*** Adding links:
(h1, s1) (h2, s1) (h3, s1) (h4, s1) (h5, s1)
*** Configuring hosts
h1 h2 h3 h4 h5
*** Starting controller
Cannot find required executable controller.
Please make sure that it is installed and available in your $PATH:
(/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
Run Code Online (Sandbox Code Playgroud)
虽然$ sudo mn --test pingall工作正常!
我想我应该找到open flow controller可执行文件并将其添加到路径中,但我不知道它位于何处.但测试创建一个控制器,工作正常!
我试图重新安装mininet
$ ~/mininet/util/install.sh -a or [-fnv]
Run Code Online (Sandbox Code Playgroud) 我使用以下(这看起来很像这个)代码下载文件:
@RequestMapping(value = "/tunes/{file_name}", method = RequestMethod.GET)
public void downloadTune(@PathVariable(value = "file_name") String tuneId,
HttpServletResponse response) {
perfomanceLogger.trace("=== Start retrieving tune with id: " + tuneId);
try {
String location = "";
// try {
location = resourceManagementService.getArtifcatByIdAndType(tuneId,
ControllerConstants.TYPE_MP3);
String pathSeparator = File.separator;
if (location == null || location.equals("")) {// load the default
// tune
location = System.getProperties().get("jboss.server.base.dir")
+ pathSeparator + ServicesConstants.FILE_LOCATION
+ pathSeparator + "ringtone_1.mp3";
if (!new File(location).exists()) {
location = "";
}
}
if (!location.equals("")) { …Run Code Online (Sandbox Code Playgroud) controller spring-mvc download spring-security illegalstateexception
好吧,我想把我的String param从下面的Play scala Route替换成我自己的对象,比如说"MyObject"
From GET /api/:id controllers.MyController.get(id: String)
To GET /api/:id controllers.MyController.get(id: MyOwnObject)
Run Code Online (Sandbox Code Playgroud)
任何关于如何做到这一点的想法将不胜感激.
我正在开发一个MVC 5互联网应用程序.我的控制器中有以下方法:
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
Run Code Online (Sandbox Code Playgroud)
如果我在这个控制器中有一个使用相同db对象的Dispose()服务类,我是否需要在这个服务类中有一个方法,或者Dispose()控制器中的方法是否需要处理这个?
提前致谢.
controller ×10
routes ×2
actionlink ×1
admin ×1
asp.net ×1
asp.net-mvc ×1
cakephp ×1
class ×1
dbcontext ×1
dispose ×1
download ×1
filter ×1
grails ×1
gsp ×1
json ×1
laravel ×1
mininet ×1
parameters ×1
python ×1
razor ×1
scala ×1
spring-mvc ×1
view ×1
wildcard ×1