controller

Reload AngularJS Controller

喜你入骨 提交于 2019-12-03 11:27:50
I'm a newbie to angularjs. My problem is that I have a User Controller for handling Login and Logout. I have also another controller to load a header menu for my site. If the user logs in to the site my isAuthenticated variable is set to true. If the variable is set to true the header should be change but, so I think the controller must be reloaded to change the header view. Here the code of my HeaderController: myapp.controller('HeaderController', ['$scope', '$location', '$window', 'AuthenticationService', function HeaderController($scope, $location, $window, AuthenticationService) { $scope

Play framework: How to require login for some actions, but not all

社会主义新天地 提交于 2019-12-03 10:05:33
问题 Adding @With(Secure.class) to a controller blocks all unauthenticated access. Is there a way to enabled it only for certain actions, or to except certain actions after it's enabled on a controller? 回答1: You can't do that with the secure module. As Niels said the secure module is more an example than a solution. You can build your own security system with the @Before annotation. Here is an example: public class Admin extends Controller { @Before(unless={"login", "authenticate", "logout",

Get controller name in TWIG template

守給你的承諾、 提交于 2019-12-03 09:53:48
问题 I am learning symfony2.3, and I am getting an error when I try to get controller name in twig template. Controller: namespace Acme\AdminBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; class DefaultController extends Controller { public function indexAction($name) { return $this->render('AcmeAdminBundle:Default:index.html.twig', array('name' => $name)); } } In my TWIG template: {% extends '::base.html.twig' %} {% block

How to get entity manager for Doctrine entity with Symfony 2.1 from inside controller

混江龙づ霸主 提交于 2019-12-03 09:26:28
How can I get an entity manager from inside a controller with latest Symfony and Doctrine? The way described in "The Book" flagged as deprecated now. What is a modern (proper) way to do this? public function someAction() { // getEntityManager() from Doctrine\Bundle\DoctrineBundle\Registry is deprecated $entityManager = $this->getDoctrine()->getEntityManager(); ... } Use $this->getDoctrine()->getManager() instead. Actually, it's best not to make controllers aware of the persistence layer you're using. That stuff should be moved to the Service Layer to abstract the way the data is persisted. 来源:

How do I generate a URL outside of a controller in ASP.NET MVC?

三世轮回 提交于 2019-12-03 09:24:22
How do I generate a URL pointing to a controller action from a helper method outside of the controller? Pass UrlHelper to your helper function and then you could do the following: public SomeReturnType MyHelper(UrlHelper url, // your other parameters) { // Your other code var myUrl = url.Action("action", "controller"); // code that consumes your url } L01NL You could use the following if you have access to the HttpContext : var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); Alexei Using L01NL's answer, it might be important to note that Action method will also get

Passing multiple result sets to a view from a controller in ASP.NET MVC?

空扰寡人 提交于 2019-12-03 09:16:24
So I have a controller set up as follows: using NonStockSystem.Models; namespace NonStockSystem.Controllers { [Authorize(Users = "DOMAIN\\rburke")] public class AdminController : Controller { private NonStockSystemDataContext db = new NonStockSystemDataContext(); public ActionResult Index() { var enumProducts = from p in db.Products select p; ViewData["Title"] = "Administration"; return View(enumProducts.ToList()); } } } The Index view on the Admin controller just lists the products in the system and allows us to click on a product to view / edit / delete it. Really simple. However each

Rspec / Capybara: Testing if a controller method is called

末鹿安然 提交于 2019-12-03 09:13:05
Given I set up a HomeController with an index action class HomeController < ApplicationController def index @users = User.all end end and routed to it via the root path, root :to => "home#index" why does this request spec fail it 'should called the home#index action' do HomeController.should_receive(:index) visit root_path end with the following message Failure/Error: HomeController.should_receive(:index) (<HomeController (class)>).index(any args) expected: 1 time received: 0 times ? Is it because the index method is called as a instance method instead of a class method? I'm not sure exactly

Laravel: Controller does not exist

强颜欢笑 提交于 2019-12-03 08:30:59
I added new controller in /app/controllers/admin/ folder and added the route in /app/routes.php file as well. Then i run the following command to autoload them php artisan dump-autoload I got the following error Mcrypt PHP extension required. I followed instruction given at https://askubuntu.com/questions/460837/mcrypt-extension-is-missing-in-14-04-server-for-mysql and able to resolve the mcrypt issue. After that i run the php artisan dump-autoload command but still getting following error {"error":{"type":"ReflectionException","message":"Class CoursesController does not exist","file":"\/var\

Devise Registration form on any page

柔情痞子 提交于 2019-12-03 07:42:48
I'm trying to allow users to sign up for the site on my home/landing page. I've duplicated the devise registration form into my landing page view- <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> <div><%= f.label :first_name %><br /> <%= f.text_field :first_name %></div> <div><%= f.label :last_name %><br /> <%= f.text_field :last_name %></div> <div><%= f.label :profile_name %><br /> <%= f.text_field :profile_name %></div> <div><%= f.label :email %><br /> <%= f.email_field :email %></div> <div><%= f.label :password %>

ActiveRecord::RecordNotFound — Couldn't find User without an ID

别说谁变了你拦得住时间么 提交于 2019-12-03 07:32:11
问题 Please see UPDATES at the bottom of the question... For reference, this problem evolved out of some fixes I made based on a previous problem I was having here: Associating Two Models in Rails (user and profile) I'm building an app that has a user model and a profile model. I want to associate these models such that: - After the user creates an account, he is automatically sent to the "create profile" page, and the profile he creates is connected to only that particular user. - Only the user