Questions tagged [controller]

A controller is responsible for executing a sequence of instructions in response to some stimulus (maybe a command, action, or event). This is often used in conjunction with the Spring or model-view-controller tags.

A controller is responsible for executing a sequence of instructions in response to some stimulus (maybe a command, action, or event). It may be used to refer to the controller portion of the MVC (Model-View-Controller) pattern, or a general handler for actions and events that orchestrates a response. It may also refer to the Spring annotation @Controller.

As it can refer to a number of different things, this tag is best used in conjunction with other tags. So, if you're referring to the Spring @Controller annotation, use the Spring tag in conjunction with this one. If you're referring to the general MVC controller, use the model-view-controller tag.

15429 questions
45
votes
2 answers

Angularjs: a Service that serves multiple $resource urls / data sources?

I have an Angular service/provider that serves json data to my controller which works great: angular.module('myApp.services', ['ngResource']). factory("statesProvider", function($resource){ return $resource('../data/states.json', {},…
Henry Zhu
  • 3,443
  • 5
  • 24
  • 36
45
votes
10 answers

AngularJs: controller is called twice by using $routeProvider

Module routes: var switchModule = angular.module('switchModule', []); switchModule.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/build-content', {templateUrl: 'build-content.html', controller:…
Howard
  • 3,814
  • 5
  • 24
  • 39
45
votes
9 answers

How can I run symfony 2 run command from controller

I'm wondering how can I run Symfony 2 command from browser query or from controller. Its because I don't have any possibility on hosting to run it and every cron jobs are setted by admin. I don't even have enabled exec() function so when I want to…
PayteR
  • 1,499
  • 1
  • 18
  • 34
43
votes
3 answers

AngularJS - Directives vs Controllers

I am trying to create my first app using AngularJS. However, I'm a bit confused if I need to use directives for my particular case. I have a simple Map page, where I need to show lat/lon value of selected region. At the moment I'm not using…
mohi666
  • 5,904
  • 8
  • 34
  • 44
42
votes
3 answers

passing JSON data to a Spring MVC controller

I need to send a JSON string to Spring MVC controller.But I do not have any form bindings to it , I just need to send a plain JSON data to Controller class.I am making jQuery AJAX call to the Controller method like the below code. $.ajax ({ …
user2702205
  • 485
  • 1
  • 7
  • 9
42
votes
9 answers

Check if in "dev" mode inside a Controller with Symfony

When using dev mode with a Symfony2.x application, one usually works in locale. Hence, such function does not works as expected (for instance, try to get the current IP under localhost). This could be a problem, e.g. when one try to use such…
JeanValjean
  • 15,832
  • 22
  • 103
  • 145
41
votes
6 answers

Rails: access controller instance variable in CoffeeScript or JavaScript asset file

In Rails 3.1 it is not possible to access controller instance variables in an asset js.erb or coffee.erb file using syntax such as <%= @foo %>, where @foo is set in the controller. So then the question is what are the best ways for passing…
Safa Alai
  • 1,053
  • 1
  • 12
  • 23
41
votes
4 answers

Why does the property I want to mock need to be virtual?

I'm doing some unit testing, and mocking some properties using Moq. Now, this is a Controller test (ASP.NET MVC 3). My Controllers derive from an abstract controller, called AbstractController. This controller has a dependency on the Http Context…
RPM1984
  • 69,608
  • 55
  • 212
  • 331
41
votes
7 answers

codeigniter check for user session in every controller

I have this private session in one of my controllers that checks if a user is logged in: function _is_logged_in() { $user = $this->session->userdata('user_data'); if (!isset($user)) { return false; } else { return…
user393964
41
votes
6 answers

Binding a Grails date from params in a controller

Why is it so hard to extract the date from the view via the params in a grails controller? I don't want to extract the date by hand like this: instance.dateX = parseDate(params["dateX_value"])//parseDate is from my helper class I just want to use…
nils petersohn
  • 1,979
  • 2
  • 22
  • 25
41
votes
3 answers

Call a model method in a Controller

I'm have some difficulties here, I am unable to successfully call a method which belongs to a ProjectPage model in the ProjectPage controller. I have in my ProjectPage controller: def index @searches = Project.published.financed …
sidney
  • 2,656
  • 3
  • 24
  • 41
40
votes
7 answers

Spring MVC Controller redirect using URL parameters instead of in response

I am trying to implement RESTful urls in my Spring MVC application. All is well except for handling form submissions. I need to redirect either back to the original form or to a "success" page. @Controller @RequestMapping("/form") public class…
user130532
40
votes
3 answers

Rails action caching with querystring parameters

How can I cache my REST controller with Rails where my actions have query string parameters? Example: GET /products/all.xml?max_price=200 Thx!
xpepermint
  • 31,091
  • 29
  • 106
  • 160
40
votes
2 answers

When can Request.Url be null?

In my controller code I am using: Request.Url.. ReSharper suggests that Request.Url can be null. So, when exactly can Request.Url be null? I am not talking about testing, I am interested only about an Application that is live / has…
Mohayemin
  • 3,761
  • 4
  • 23
  • 51
40
votes
4 answers

One controller rendering using another controller's views

I have QuestionController I now have AnotherQuestionController with actions which should render using templates and partials in app/views/question/ Is this possible? Seems like it should be. I've tried render :template => "question/answer" but…
Paul
  • 981
  • 2
  • 11
  • 18