How can i use custome class in SYmfony 2 ?
I created class "Social" where i defined the namespace "namespace W4Pro\Social Bundle\Class" and located in directory "W4Pro\SocialBundle\Class". Now i want to use this class in my controller "W4Pro\SocialBundle\Controller\DefaultController", i used this "use W4Pro\SocialBundle\Class\Social;" but when i run the page i received the error
Cannot import resource "C:\xampp1\htdocs\test\src\W4Pro\SocialBundle/Controller/" from "C:/xampp1/htdocs/test/app/config\routing.yml". (Class W4Pro\SocialBundle\Controller\Social does not exist)
Related
I'm trying to create a new Symfony4 project with MongoDB.
First I created a Symfony4 project using this documentation:
https://symfony.com/doc/current/setup.html
Then I included MongoDB using this documentation:
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
I tried to follow the instructions as exactly as possible (for example I didn't need to add anything to app/AppKernel.php, but MongoDB was automatically added to config/bundles.php).
Now I think everything should work, but my Symfony app doesn't find the MongoDB Service:
You have requested a non-existent service "doctrine_mongodb".
Did you mean one of these: "http_kernel", "request_stack", "router"?
in ServiceLocator.php (line 48)
Controller:
namespace App\Controller;
use App\Document\Chapter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends AbstractController {
public function createAction() {
$test = new Chapter();
$test->setHeadline('Test');
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($test);
$dm->flush();
return new Response('Created product id '.$test->getId());
}
}
However, If I execute this on the console:
php bin/console debug:container
I get a list of services including these:
doctrine_mongodb Doctrine\Bundle\MongoDBBundle\ManagerRegistry
doctrine_mongodb.odm.default_connection Doctrine\MongoDB\Connection
doctrine_mongodb.odm.default_document_manager Doctrine\ODM\MongoDB\DocumentManager
doctrine_mongodb.odm.document_manager alias for "doctrine_mongodb.odm.default_document_manager"
So the service seems to be there, but Symfony can't load it from my app.
Any idea how I could solve this?
Is it possible that the Mongo-DB Server connection doesn't work and for some reason it isn't logged and the service just won't load?
You could use autowiring
use Doctrine\ODM\MongoDB\DocumentManager as DocumentManager;
and
public function createProduct(DocumentManager $dm)
Try extending from "Controller" instead "AbstractController".
class DefaultController extends Controller
I have tried to add product with bundle type that time getting error like below.
Could not save child: "Unknown entity type: Magento\Bundle\Model\Selection\Interceptor requested"
i got same issues for this trouble, i resolved by add interface : Magento\Framework\ObjectManager\NoninterceptableInterface to
Magento\Bundle\Model\Selection
the final class define look like:
class Selection extends \Magento\Framework\Model\AbstractModel implements
\Magento\Framework\ObjectManager\NoninterceptableInterface
Change
class Selection extends \Magento\Framework\Model\AbstractModel
to
class Selection extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\ObjectManager\NoninterceptableInterface
on below file
vendor/magento/module-bundle/Model/Selection.php
I'm using laravel 4.0 for my web service project. I try to assign relative path to controller subfolder but still got the error message.
This is my router looks like
Route::group(array('prefix' => 'merchant'), function()
{
Route::resource('index', 'ProductController#showIndex');
Route::resource('product', 'CategoryController#showIndex');
Route::resource('general', 'GeneralController#showIndex');
});
Current path
/app/controllers/ProductController.php
I want to be like this one
/app/controllers/merchant/ProductController.php
Thanks a lot in advance.
You need a namespace to achieve that.
In your controller folder make a directory called merchant and place your ProductController.php inside Merchant directory.
Then open your ProductController.php and use the following namespace on top of the file.
<?php namespace Merchant;
class ProductController extends /BaseController
{
After that edit your route file:
Route::get('index', 'Merchant\ProductController#showIndex');
Remove the Route::group(array('prefix' => 'merchant'), function(). Prefix used when you have a common url for more than one routes.
For example:
http:://laravel.com/xyz/products
http:://laravel.com/xyz/category
http:://laravel.com/xyz/posts
Here xyz is common in every URL. So, In this case, you can use group routing with prefix xyz
One more thing, I can see, you have used resource controller.
Route::resource('index', 'ProductController#showIndex');
Route::resource('product', 'CategoryController#showIndex');
Route::resource('general', 'GeneralController#showIndex');
Do you know that By default, for resource controller, Laravel will generate 7 routes. So, You don't need to create #showIndex function when using resource controller.
Route::resource('index', 'ProductController');
Route::resource('product', 'CategoryController');
Route::resource('general', 'GeneralController');
More about resource controller:
http://laravel.com/docs/controllers#resource-controllers
i wrote own decorator in the app path like "library/myLib/Form/Decorator/Lalala.php"
now suppose to use it like $element->addDecorator('Lalala');
but get error:
Plugin by name 'Filechoose' was not found in the registry; used paths:
Zend_Form_Decorator_: Zend/Form/Decorator/
how to set up default element decorator paths.
Assuming that your decorator class myLib_Form_Decorator_Lalala is stored in file library/myLib/Form/Decorator/Lalala.php, then we can do it as follows:
At the form level:
$form->addElementPrefixPath(APPLICATION_PATH . '/../library/myLib/Form/Decorator', 'myLib_Form_Decorator_', Zend_Form::DECORATOR);
At the element level:
$elt->addPrefixPath(APPLICATION_PATH . '/../library/myLib/Form/Decorator', 'myLib_Form_Decorator_', Zend_Form::DECORATOR);
My application setup with 2 modules admin and default
I test the controller which works fine on modules
but the models doesnt work
I created a model application\modules\admin\models\User.php
<?php
class Admin_Model_User{
}
inside the controller
$user = new Admin_Model_User();
Fatal error: Class 'Admin_Model_User'
not found
Essentially, you need 2 lines in the application.ini file;
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
Then, for each module, you need a module bootstrap file:
File: myproject/application/modules/{modulename}/Bootstrap.php
<?php
class {Modulename}_Bootstrap extends Zend_Application_Module_Bootstrap
{
}
(Yes, it is an empty class.)
Further details are at http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/.
Configure an autoloader so that the framework can map your class prefix Admin_Model to the corresponding source path. This is not done automatically.
I suggest reading the part on models of the Zend Framework Quickstart, which explains in detail how to do this.
Are you using an autoloader?
If you do you should change the class name (or path) to reflect the path (or class name)
Models <> Model
You should have
Admin_Model_User in admin/model/user.php
or
Admin_Models_User in admin/models/user.php.