开始使用symfony并遇到服务问题。
... \应用\配置\ services.yml
app.pdf.service:
class: AppBundle\Service\PdfService
arguments: [format, orientation]]
... \ SRC \的appbundle \服务\ PdfService.php
namespace AppBundle\Service;
class PdfService
{
private $format;
private $orientation;
public function __construct($format, $orientation)
{
$this->format = $format;
$this->orientation = $orientation;
}
}
现在我尝试使用以下服务:
$this->container->get('app.pdf.service');
我忘记了什么吗? $ this-> container-> get(ist working,因为我从whiteoctober / tcpdf-bundle调用了tcpdf / Service。我将扩展此服务,因为我需要更多的功能。
任何提示? cu s00n n00n
答案 0 :(得分:0)
假设您的参数中定义了格式和方向,请尝试:
Description
"硬编码"定义示例:
'use strict'
import _ from 'moar-lodash'
import Promise from 'bluebird'
import Mongoose from 'mongoose'
import Async from 'async'
import Util from 'util'
import * as appRoot from 'app-root-path'
Mongoose.Promise = Promise
Mongoose.connect( appRoot.require('./dist/lib/config').database.connection )
const accountLib = appRoot.require('./dist/lib/account')
const models = require( '../models' )( Mongoose )
models.Asset.getAsset( '56d0819b655baf4a4a7f9cad' )
.then( assetDoc => {
var jqDoc = JSON.parse(JSON.stringify(assetDoc.toJSON()))
// Show the CURRENT description
console.log('[IN QUERY - Before Modify]\n\t', jqDoc.attributes[1].value)
assetDoc.attr('Description').set( 'Date-'+Date.now() )
return assetDoc.save()
} )
.then(data => {
// Just show the Description AFTER it was saved
console.log('[AFTER QUERY - AFTER Modify]\n\t', data.attributes[1].value)
})
.catch( err => console.error( 'ERROR:',err ) )
.finally( () => {
Mongoose.connection.close()
console.log('# Connection Closed')
})
[IN QUERY - Before Modify]
Date-1474915946697
[MIDDLEWARE ORIGINAL Desc]
Date-1474916372134
[MIDDLEWARE NEW Desc]
Date-1474916372134
[AFTER QUERY - AFTER Modify]
Date-1474916372134
# Connection Closed
查看官方文档以获取更多详细信息: https://symfony.com/doc/current/components/dependency_injection.html#setting-up-the-container-with-configuration-files