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.
Related
I need to call a specific method in a controller that returns a value, from within a library, but all I found so far is redirecting to a route like this :
redirect('Controller1/method1')
And this is not what I need, I don't want to redirect to a route but get a value from the called method.
Calling controller method from library, may be not a correct approach.
Any how try below 2 solutions
Solution #1
Create CodeIgniter object and try to access the method required
$this->CI = & get_instance();
$this->CI->requiredMethod()
Solution #2
Try this in least case
Include required controller in the library file
include_once 'application/controllers/YourController.php';
Create obj and call
$obj = new YourController();
$obj->requiredMethod()
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.
I am trying to pass data from my controller to my view, but am getting an undefined variable error. usersID is a column in my MySQL table.
Here is the code in my controller
$arrayWithCount = DB :: table("users_has_activities")
-> where("usersID", "=", 19)
-> pluck("usersID");
$countNumber = sizeof($arrayWithCount);
return view('pages.progress', ['countNumber' => $countNumber]);
I have also tried the following return statement without any success
return view::make('pages.progress') -> with('countNumber', $countNumber);
I have also tried reversing the puck and where clauses without any success, I didn't have high hopes that reversing them would fix the problem but thought I would try it any way. Below is the relevant code in the blade file.
<?php echo $countNumber; ?>
This is the error I am currently getting
Undefined variable: countNumber
You code looks fine, if dd() doesn't stop execution of the controller, then another controller is executing. So double check your routes and controllers.
First sizeof should be sizeOf, and is simply an alias for count(). Most people would prefer count over sizeOf as sizeOf (in many languages) would indicate something related to size on disk.
Anywho, being that pluck returns a collection, you have access to count() directly from the collection.
You can probably simply do something like:
$countNumber = $arrayWithCount->count();
Sidenote: Unless there is a particular reason why you are using <?php ?>, in blade, it would be preferred to use {{ and }}.
I had all the controller code in a method I wasn't calling, so the variable was never passed to the blade file. The method was set up to be called on a button press, after fixing that everything works. Thanks Alexey for the help.
I have a controller name CodeBridgeController and have a model table name CodeBridgeTable.
When I call CodeBridge table in action like following:
$this->CodeBridge->find('all')->toArray();
This generate Error: Call to a member function find() on a non-object
File D:\php\htdocs\cake3\erp\src\Controller\CodeBridgeController.php
Line: 25
I think this is silly matter but i could not find any wrong in the code why table is not loaded in this context.
When i call this way it works.
$codeBridgeTable = TableRegistry::get('CodeBridge');
$results = $codeBridgeTable->find('all')->hydrate(false)->toArray();
What may create the problem, expert suggestion needed.
Finally, I found where the problem lies.
In controller action, I generating a url like following:
Router::url(array('controller' =>'codebridge','action'=>'edit')); which generate url /cake3/erp/codebridge/edit
After changing the controller name in camel case Router::url(array('controller' =>'CodeBridge','action'=>'edit')); which generate url '/cake3/erp/code-bridge/edit`
This solve the problem
To resolve this, just load the model prior to trying to use it:
$this->loadModel("CodeBridge");
$this->CodeBridge->find('all')->toArray();
Hi a Laravel beginner here, I have a a manual select query which retrieve the data correctly via DB::select.
Now I want to paginate the result, however manual pagination doesn't work
$pagination = Paginator::make($book, count($book), 5);
and returning the following error
Call to undefined method Illuminate\Pagination\Paginator::make()
I am using Laravel 4.2
Please help
Thanks
You are using the wrong Paginator class. You should change your import to:
use Illuminate\Support\Facades\Paginator;
Or remove the use statement completely since there's an alias registered for just Paginator