Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can findAll function in modeling data accept 3rd parameter reset #3024

Closed
engrsandeep opened this issue May 20, 2020 · 2 comments
Closed

Can findAll function in modeling data accept 3rd parameter reset #3024

engrsandeep opened this issue May 20, 2020 · 2 comments

Comments

@engrsandeep
Copy link

Sometime, we need to generate just of count all results after getting limited records for pagination. Is it possible to add 3rd parameter in find all function in modeling data and update it like below. code which is working fine, or provide a function to set reset function at model level, so it can be done on/off as required.

/**
* Works with the current Query Builder instance to return
* all results, while optionally limiting them.
*
* @param integer $limit
* @param integer $offset
* @param boolean $reset
*
* @return array
*/
public function findAll(int $limit = 0, int $offset = 0,$reset = true)
{
$builder = $this->builder();

	if ($this->tempUseSoftDeletes === true)
	{
		$builder->where($this->table . '.' . $this->deletedField, null);
	}

	$row = $builder->get($limit, $offset,$reset);

	$row = $row->getResult($this->tempReturnType);

	$eventData = $this->trigger('afterFind', ['data' => $row, 'limit' => $limit, 'offset' => $offset]);

	$this->tempReturnType     = $this->returnType;
	$this->tempUseSoftDeletes = $this->useSoftDeletes;

	return $eventData['data'];
}

Many thanks for making Codeigniter 4 in good shape.

@enix-app
Copy link
Contributor

I have a custom pagination model library and I think the 3rd param can solve my problem.

@michalsn
Copy link
Member

In the described use case, you should first use countAllResults(false) method. Parameter false will prevent resetting the query. After this, you can use findAll() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants