I inserted some data into the database but my issue is when I want to retreive it.
I followed the official documentation with findOneById method, findAll method and I getting the following error
Attempted to call an undefined method named "findAll" of class "Doctrine\ODM\MongoDB\Query\Builder
My controler is like below:
$export = $this
->get('doctrine_mongodb')
->getManager()
->createQueryBuilder('NeoNasaBundle:Neorepo');
$aff = $export->findAll();
I need to finish a project before tonight and It becomes trickly...
If you want some detail, I will EDIT this post
Thanks for support
Assuming you are using the latest DoctrineMongoDBBundlerthen you should be accessing find(), findOneById(), findOneByName() or findAll() through a repository object. Using your example:
$export = $this->get('doctrine_mongodb')
->getManager()
->getRepository('NeoNasaBundle:Neorepo')
$aff = > $export->findAll();
If this doesn't help, you need to provide version of Doctrine and MongoDB.
Related
I'm working on a old PHP project, that is running in legacy SQL query, which is good but I like to use query builders like Laravel Illuminate SQL package!
So i have added all required package dependencies to run Illuminate SQL, and this query builder seems to work fine with pagination!
$users = Capsule::table('users')->paginate(1)->toArray();
But, the paginator seems not to be able to listen the query string! For example, by running the above code it would give some properties like, next_page , previous_page etc...
And when I try to pass the query string in the URL it can't fetch the data from query string(From the GET request)!
Visiting this page http://app.app/?page=2 would give the same result set.
How i should configure the Illuminate sql package so it can also listen to the query strings?
EDIT
Also, i've tried to use the illuminate/http package, but the $request->all() method always returns an empty array! Here is the code:
<?php
require_once './vendor/autoload.php';
use \Illuminate\Http\Request;
$req = new Request();
echo '<pre>';
print_r($req->all());
echo '</pre>';
It returns empty input data array,
What i am missing to use the http package, any idea would be helpful.
You have to set a page resolver:
\Illuminate\Pagination\Paginator::currentPageResolver(function ($pageName = 'page') {
return (int) ($_GET[$pageName] ?? 1);
});
Laravel uses this resolver.
You need to notice, that paginator won't use other parameters for query string - it just uses page parameter to get valid results page. But for example if you use:
http://app.app/?page=2&price=2
it won't take from database results with price = 2 - it's your job to do this.
However the 2nd thing are urls generated by paginator.
If you do it like this:
$users = Capsule::table('users')->paginate(1);
You can also use in next line
$users->appends(request()->except('page'));
This will add all other parameters from query string (except page) to urls, so first_page_url will then contain all other parameters from request.
You can also wrap it using fluent syntax like this:
$users = Capsule::table('users')->paginate(1)->appends(request()->except('page'));
You need to fetch the query string in the controller to pass the get parameter to
paginate.
You can use the Illuminate\Http\Request class to receive and use the HTTP payload.
Your controller file:
<?php
use Illuminate\Http\Request;
class YourControllerClassName{
public function someFunction(Request $request){
echo "<pre>";
print_r($request->all());
print_r($request->input('page'));
$users = Capsule::table('users')->paginate($request->input('page'))->toArray();
}
}
I'm using Kohana and I'm trying to delete some data in my database. So, I made a request like this :
$env_sol = ORM::factory('EnvironnementSol')
->where('sol_id','=',$id)
->and_where('environnement_id','=', $id_environnement->id)
->find_all();
$env_sol->delete();
And I run the page, it tells me :
Call to undefined method Database_MySQLi_Result::delete()
Can someone tell me why please ?
Instead of using ORM class you can use DB class for that purpose.
DB::delete('EnvironnementSol')
->where('sol_id','=',$id)
->and_where('environnement_id','=', $id_environnement->id)
->execute();
The object pointed to by $env_sol is of type Database_MySQLi_Result which does not have a delete() method.
I have problem with phalcon framework namely with models methods...
As you know models has included methods find() and findFirst()
I have generated model with phalcon-dev tools and now I am trying to do Model::find on it but I am getting an exception but dont know why...
There is some more informations (e.g stacktrace) :
http://exception.mateuszmarzecki.pl/
You can try change methods in model file
public static function find($parameters = array())
{
return self::find($parameters);
}
Does not look like your passing it the right parms.
SELECT FROM `nacionality`
Notice that your not selecting any fields from the database, and that is why your getting the Exception.
So... after some time of debugging I've found the problem...
For the next generation... if you don't want to lose a week as I did. Just read carefully your application config.
Problems occurs because I missed table and column annotations as well.
In my application config I have something like:
$metaData->setStrategy(new \Engine\Db\Model\Annotations\Metadata());
so Phalcon was looking for annotations in my model files, more info about this you can find there:
https://forum.phalconphp.com/discussion/1933/column-types-for-model-annotations
Happy New Year
Hi I'm building a project from symfony and doctrine
I'm trying to access the data in a fetched object. As an example I want to retrieve data in the $products object
$products = $repository->findByPrice($price);
I've tried $prodcuts[0], $prodcuts['pName']
Nothing seems to work. A little advice would be very helpfull
Make sure the namespace and use statements are pointing to correct files, then:
$product = $this->getDoctrine()->getRepository('bundleName:tableEntity')
->findByPrice($price);
Then for instance you can further use
echo $product->getPrice();
You can then handle the object instantiated as per your need..
I'm creating a behavior that log to a table the sql query executed by a particular Model in a controller. Looking for a method to return me the sql query executed for a particular finder method (like $this->MyModel->find('all') ) I found on the bakery that I can use $this->MyModel->find('sql'), but doesn't work for me. Someone knows how can I achieve this?
Thanks in advance
You can put this function in your app_model.php:
function getLastQueries()
{
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;
return $logs;
}
And call it from any model ($this->getLastQueries()) or controller ($this->Model->getLastQueries()) to get them.
$this->Model->find('sql') is not supported natively by Cake. You have to follow the rest of the instructions in the Bakery article for installing a new DBO driver, and adding support for the find('sql') method in your AppModel. Once you do this, it should be able to get you what you're looking for.
http://bakery.cakephp.org/articles/grant_cox/2008/06/23/get-the-find-query-sql-rather-than-query-result