Doctrine Entity from other Bundle in Symfony Controller - php

I try to use the Entity of another Bundle in my Symfony Controller:
use Acme\TestBundle\Entity\Neighbour;
use AppBundle\Entity\Home;
class TestController extends Controller {
public function testAction(Home $home, Neighbour $neighbour) {
//
}
}
but this throws an 404 Error:
Acme\TestBundle\Entity\Neighbour object not found
this is different to a real not existing object like NeighbourX, there it throws an 500 error:
Acme\TestBundle\Entity\Neighbour does not exist
The object exists, and it should work, because this works:
use Acme\TestBundle\Entity\Neighbour;
use AppBundle\Entity\Home;
class TestController extends Controller {
public function testAction(Home $home) {
$thread = new ForumThread();
}
}

Ok I already found the answer myself. I had to specify the route variable:
/home/{id}/neighbour/{nid} #before
/home/{id}/neighbour/{neighbour} #after
But I don't fully understand it. Why doesn't {id} has to be {home}? Is {id} just the first parameter-id by default?
And why is the error message that misleading..

Related

The controller for URI {url} is not callable

currently I am learning Pimcore which is made with Symfony (and I am a Laravel guy :3 ) So I have his error:
The controller for URI "/article/1132/This%20is%20my%20first%20post%20in%20Pimcore" is not callable:
Expected method "blogarticleAction" on class "AppBundle\Controller\DefaultController".
I am trying to get an object (of blogpost) based on its ID and then to display that blogpost to the user.
I have made that controller with blogarticleAction method:
<?php
namespace AppBundle\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Pimcore\Model\DataObject;
class MyContentController extends FrontendController
{
public function defaultAction(Request $request)
{
//$this->view->blogpostList = new DataObject\Blogpost\Listing();
$list = new DataObject\Blogpost\Listing();
$paginator = new \Zend\Paginator\Paginator($list);
$paginator->setCurrentPageNumber( $request->get('page') );
$paginator->setItemCountPerPage(3);
$this->view->paginator = $paginator;
}
public function blogarticleAction(Request $request)
{
$this->view->blogarticle = DataObject\Blogpost::getById($this->getParameter('id'));
}
}
Also, here is my static route from the Pimcore admin panel:
https://prnt.sc/w96ya3
Links seem to be formed correctly:
https://prnt.sc/w96zvn
but when I click on that link to go to a single blogpost I get this:
https://prnt.sc/w970kg
The error states that the method should exist on DefaultController and not on MyContentController. In the screenshot of your static route, you have used the DefaultController only.

Pimcore 4 extending Document/Page

Again I am having trouble getting the class mappings to work in Pimcore 4. This time I want to extend the document page class. This used to work without problems in older versions, but now I cannot get it working.
I copied this example in classmap.php from classmap.example.php:
website/config/classmap.php:
return [
"Document\\Page" => "Website\\Model\\Document\\Page",
]
website/models/Website/Model/Document/Page.php:
namespace Website\Model;
use Pimcore\Model\Document;
class Page extends Document\Page {
public function getPublicPath() {
return $this->getFullPath();
}
}
The expected result is that I can call getPublicPath() on every document\page object. But this is not working. Instead I get the following error:
Call to undefined method getPublicPath in class Pimcore\Model\Document\Page
How do I get this working?
Your namespace declaration is wrong. It should be:
namespace Website\Model\Document;
So the whole class looks like this:
<?php
namespace Website\Model\Document;
use Pimcore\Model\Document;
class Page extends Document\Page {
public function getPublicPath() {
return $this->getFullPath();
}
}
Don't forget to clear the cache after updating your code!

Laravel error: Target [Illuminate\View\Engines\EngineInterface] is not instantiable

I'm creating an abstract class that will grab the contents of a view using Laravel's View class. But I'm getting the following error when trying to run a method from a class that extends it:
Illuminate \ Container \ BindingResolutionException
Target [Illuminate\View\Engines\EngineInterface] is not instantiable.
Here's my code:
PdfReport.php
use Illuminate\View\View as View;
abstract class PdfReport {
private $view;
function __construct(View $view)
{
$this->view = $view;
}
public function render($reportView, $report)
{
$this->view->make('report.pdf.' . $reportView, ['report' => $report])->render();
}
}
EslReport.php
<?php namespace Reports\PdfReports;
class EslPdfReport extends PdfReport {
public function renderReport($report)
{
return $this->render('esl', $report);
}
}
Then I'm running my code in routes.php for testing purposes as follows:
use Reports\PdfReports\EslPdfReport;
Route::get('pdftest', array(
'as' => 'pdftest',
function(){
$eslReport = App::make('Reports\PdfReports\EslPdfReport');
$eslReport->renderReport(EslReport::find(1));
}
));
I'm not quite understanding if I'm doing something wrong with the dependency injection for the view in the abstract class, it's all pretty new concepts to me, so any help would be most appreciated.
Also I asked this question on laracasts forum if it helps: https://laracasts.com/discuss/channels/general-discussion/confusion-about-constructors-in-abstract-classes
Instead of Illuminate\View\View you need to inject Illuminate\View\Factory:
use Illuminate\View\Factory as View;
Here's a reference of facade classes and there actual underlying class you need to use when working with DI

FuelPHP simple class Not Found Error

This is my first deployment of FuelPHP, though I am a long time user of CodeIgniter.
I am getting the following error when I load the page:
ErrorException [ Fatal Error ]:
Class 'Model\Model_UPS' not found
/classes/controller/ups.php
<?php
use \Model\Model_UPS;
class Controller_UPS extends Controller {
public function action_index() {
$view = View::forge('json');
$view->title = Model_UPS::get_load();
return $view;
}
}
?>
/classes/model/model_ups.php or ups.php
<?php
namespace Model;
class Model_UPS extends \Model {
public static function get_load() {
return "This is the load!";
}
}
?>
/views/json.php
<?=$title;?>
The error page highlights the $view->title = Model_UPS::get_load(); line of ups.php. I have tried just about every configuration of use, namespace, model filename, and model class name that I can think of. I can't seem to find a super simple MVC example to use as a guide. I've tried to duplicate the FuelPHP Docs as best as I can, but have failed. Can anyone find anything wrong with this?
Rename file: model/model_ups.php to model/ups.php
Rename class: Model_UPS to UPS
Change: use \Model\Model_UPS; to use \Model\UPS;
Change: Model_UPS::get_load(); to UPS::get_load();

Gas ORM - class not found

I was trying out Gas ORM, and have managed to auto-generate my models and now need to test them. However, I cannot seem to access the newly generated model.
I have the library autoloaded, and the config set up as:
config/gas.php
$config['models_path'] = array('GasModel' => APPPATH.'gas');
gas/useraccounts.php
<?php namespace GasModel;
/* This basic model has been auto-generated by the Gas ORM */
use \Gas\Core;
use \Gas\ORM;
class UserAccounts extends ORM {
public $primary_key = 'id';
function _init()
{
self::$fields = array(
'id' => ORM::field('auto[11]'),
...
);
}
}
controller/user.php
public function test() {
GasModel\UserAccounts::all()
}
Trying to access it however throws a fatal error:
PHP Fatal error: Class 'GasModel\UserAccounts' not found in applications/controllers/user.php on line 28
Can anyone help me in solving this issue?
Try add use of your model namespace or try add \ before GasModel
When I used back the same namespace as the example in http://gasorm-doc.taufanaditya.com/configuration.html, which is Model, it started working mysteriously. I would have preferred to use my custom namespace though..

Categories