我在Symfony项目中遇到很多问题。我的最后一个问题是当我尝试清理缓存时:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new HomeBundle\HomeBundle(),
new UserBundle\UserBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle();
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
console return me:
[Symfony的\元器件\配置\异常\ FileLoaderLoadException]
无法加载资源“@ UserBundle / Controller /”。确保 “UserBundle”包已正确注册并加载到 应用程序内核类。如果捆绑包已注册,请确保 包路径“@ UserBundle / Control ler /”不为空。
我认为我有正确的AppKernel和routing.yml: AppKernel:
user:
resource: "@UserBundle/Controller"
type: annotation
prefix: /user
home:
resource: "@HomeBundle/Controller"
type: annotation
prefix: /
NelmioApiDocBundle:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /api/doc
的routing.yml:
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=-1.3070491136606004,36.824679896235466&destinations=-1.3074272067017922,36.82789519429207";
RequestQueue mRequestQueue;
Cache cache = new DiskBasedCache(getActivity().getCacheDir(), 1024 * 1024); // 1MB cap
final Network network = new BasicNetwork(new HurlStack());
mRequestQueue = new RequestQueue(cache, network);
mRequestQueue.start();
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println("Response" + response);
JSONObject jsonObject;
JSONArray jsonarray;
try {
jsonObject = new JSONObject(response);
jsonarray = jsonObject.getJSONArray("rows");
for (int i=0; i<jsonarray.length(); i++)
{
JSONArray jsonArray = jsonarray.getJSONArray(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
return params;
}
};
// Add the request to the RequestQueue.
mRequestQueue.add(stringRequest);
我认为这个问题在我的网站上给了我一个索引。
答案 0 :(得分:0)
我发现错误,是SensioFrameworkExtraBundle声明错误:
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
//this bundle must be here
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle();
new HomeBundle\HomeBundle(),
new UserBundle\UserBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true))
//remove SensioFrameworkbundle
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}