2016-12-20 6 views
0

내가 SailsJs 새로운 그리고 난 예를 들어, 기본 방법 생성 된 비계를 통해 재정의를 수행 할 재정의 컨트롤러 기본 방법 :SailsJs -

만들기 그래서 아이디어가있다 create를 호출하기 전에 someStuff()를 수행하십시오. 기본적으로 스캐 폴딩 후에 나오는 기본 생성 전에 몇 가지 기능을 추가하지만 코드를 다시 작성하지 않도록 해당 기능을 호출하고 싶습니다.

다음은 내가 실행하는 명령입니다. 여기

/** 
* UserController 
* 
* @description :: Server-side logic for managing users 
* @help  :: See http://sailsjs.org/#!/documentation/concepts/Controllers 
*/ 

module.exports = { 
    create: function (req, res) { 
    someStuff(); 
    call_to_default_create()<--- What to know if posible? 
    },   
}; 

모델 코드 :

/** 
* User.js 
* 
* @description :: TODO: You might write a short summary of how this model works and what it represents here. 
* @docs  :: http://sailsjs.org/documentation/concepts/models-and-orm/models 
*/ 

module.exports = { 
    attributes: { 
    name: { 
     type: 'string', 
     required: true, 
     minLength: 2 
    }, 
    last_name: { 
     type: 'string', 
     required: true, 
     minLength: 2 
    }, 
    email: { 
     type: 'string', 
     email: true, 
     required: true, 
     unique: true 
    }, 
    encrypted_password: { 
     type: 'string' 
    } 
    } 
} 

내가 항해를 작동하는 방법은 상속이 아니라고 생각하지만 난 어떻게 든이를 에뮬레이션 할 수 있습니다 여기에

sails generate api user 

내 컨트롤러 코드 ?

답변

1

당신은 sails.hooks.blueprints.middleware.create(req, res);을 찾고 있습니다. 그래서 사용자 정의 create 방법은 다음과 같습니다 나는 청사진이 실제로는하지만, 어디 문서화 같이 오버라이드 (override) 발견, 그래서 자신의 위험에 사용할 수 없습니다

/** 
* UserController 
* 
* @description :: Server-side logic for managing users 
* @help  :: See http://sailsjs.org/#!/documentation/concepts/Controllers 
*/ 

module.exports = { 
    create: function (req, res) { 
    someStuff(); 
    return sails.hooks.blueprints.middleware.create(req, res); 
    },   
}; 

. =)

+0

감사합니다. 적용 해본 결과 작동합니다. –