Codeigniter Pagination cannot initialize - codeigniter

Here is the controller ....
public function viewdeals (){
$this ->load-> model ('model_dealview');
if ( $q1 = $this-> model_dealview-> getdeals()){
$this->load->library('pagination');
$config['base_url'] = 'formalert/viewdeals';
$config['total_rows'] = 40;
$config['per_page'] = 5;
$this->pagination->initialize($config);
$q1['pagination'] = $this->pagination->create_links();
$this -> load -> view ('view_deals', $q1);
}
The problem is that whenever I try to run this with pagination ... i get this error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Contoller_name::$pagination
Fatal error: Call to a member function initialize() on a non-object in
C:\wamp\www\ci\application\controllers\controllerfile_name.php on line 108
Everything works fine without pagination ...
I have tried loading library in cofig file ... done pretty much everything .. even copied code from the internet that work for other people .. Need help! ...
Please note its not identifying the property $pagination ... so other small problems in teh code won't matter.

Ok problem solved. You need to autoload the pagination library... just loading it in the function will not do.

Related

How to Route Codeigniter with URI Segments there

how to route properly url with segments in codeigniter.
this is my url .
https://www.test.com/region/india/about/people/gaurav-Singh/1
this is in my route
$route['region/india/about/people/(:any)/(:any)'] = "region/india/memberview/$1/$2";
this is my controller
public function memberview()
{
$teamid = $this->uri->segment(5);
$data['view'] = 'region/india/team-member-view.php';
$this->load->model('region/India_model');
$data['team'] = $this->India_model->tmview($teamid);
$this->load->view('region/layout', $data);
}
this is my model
public function tmview($teamid){
$this->db->query("select * from ojiteam");
$this->db->where('id',$teamid);
$query = $this->db->get();
return $query->result_array();
}
in my view i am showing data with
<?php echo $team['tmname'];?>
but its not working, it is showing 500 error.
help me with this issue. i have searched and went through codeigniter but not able to solve this.
Depending on the environment you are working on (see docs) you can debug to figure out what is causing this 500 error. Usually this means somehting is wrong with your code, you will have to debug to find out what file and line this error is generated from.
To use numbers in your routing you should do (:num), this way only numbers are allowed on that part of your routing (see docs).
On the controller part, you can pass variables to your controller from your routing options, so;
$route['region/india/about/people/(:any)/(:any)'] = "region/india/memberview/$1/$2";
public function memberview( $area, $teamid )
{
// Your coding
// $area now is; gaurav-Singh
// $teamid now is; 1
}
This way you don't have to worry about which part of the URL you need to use because it's all set.

Laravel 5.4 - Adldap - Call to undefined method Adldap\Adldap::search()

I have an issue with my Laravel installation and the use of Adldap...
The error message I receive :
FatalThrowableError in UserCreationController.php line 100:
Class 'App\Http\Controllers\Adldap' not found
I have installed/deployed Adldap according to the documentation and it is working when I call it from some other location.
Working stuff :
Route::get('ldap', function() {
$results = Adldap::search()->where('ou', 'ends_with', ' Users')
->orWhere('ou','not_contains', 'Production')
->sortBy('ou', 'asc')
->get();
foreach ($results as $result) {
dump ($result->ou);
}
The page displays the dump correctly. All is fine.
Not working stuff (yields error code listed above).
Route calling a Controller...
Route :
Route::get('newuser', 'UserCreationController#GetUserOrganizationalUnits');
Controller :
public function GetUserOrganizationalUnits()
{
$results = Adldap::search()->where('ou', 'ends_with', ' Users')
->orWhere('ou','not_contains', 'Production')
->sortBy('ou', 'asc')
->get();
return view('newuserform',compact('results'));
}
Why is it working from the web php with the routes directly but not from the called Controller?
I already try adding explicitely the following as well...
use Adldap\Contracts\AdldapInterface;
The facade is declared and it works in the web routes without even calling this...
Can you please help ?
Thanks.
I think you forgot to include the Facade
Add: use Adldap; in your UserCreationController.php
You'll also need to have this in your UserCreationController to get this working with the "use Adldap\Contracts\AdldapInterface;" approach:
protected $adldap;
public function __construct(AdldapInterface $adldap)
{
$this->adldap = $adldap;
}
Or implement the facade in your config/app.php:
'Adldap' => Adldap\Laravel\Facades\Adldap::class

Render Partial TemplateView in Typo3 using Extbase

I want to lazy load several PartialTemplates in an Extbase Controller via Ajax.
Therefore I found the following script to render only a Partials but it doesn't work in my context:
private function renderPartial($partialName='', $data = array()){
if($partialName==''){
throw new \TYPO3\CMS\Extbase\Mvc\Exception\RequiredArgumentMissingException('The Partial name must be defined.', 123456789);
}
$this->templateView = $this->objectManager->create('TYPO3\CMS\Fluid\View\TemplateView');
$res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
$this->templateView->setLayoutRootPath($res);
$this->templateView->setPartialRootPath($res . 'Partials/');
$this->templateView->setRenderingContext($this->objectManager->create('TYPO3\CMS\Fluid\Core\Rendering\RenderingContext'));
$this->templateView->setControllerContext($this->controllerContext);
return $this->templateView->renderPartial($partialName, Null, $data);
}
This results in the following Error:
Fatal error: __clone method called on non-object in /var/www/html/typo3_src-7.6.0/typo3/sysext/fluid/Classes/View/AbstractTemplateView.php on line 281
I Goolge for this and found many posts having the same problem. What can I do to make this working. A workaround using the StandaloneView and setTemplatePathAndFilename() works well. Is it possible to use Partial without a Layout/Section?
EDIT:
I added some debug Informations and the Controller Action...
public function searchAction(\PCON\Avm\Domain\Model\DemandSearch $demandSearch = NULL) {
//GlobalSearch
if($demandSearch != NULL) {
$searchResult = $this->demandSearchRepository->findDemanded($demandSearch);
$this->view->assign('searchResult', $searchResult);
}
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->controllerContext);
$this->templateView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\TemplateView');
$res = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->controllerContext->getRequest()->getControllerExtensionKey()) . 'Resources/Private/';
$this->templateView->setLayoutRootPath($res);
$this->templateView->setPartialRootPath($res . 'Partials/');
$this->templateView->setRenderingContext($this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext'));
$this->templateView->setControllerContext($this->controllerContext);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->templateView);
return $this->templateView->renderPartial('Search/SearchForm.html', Null, array('searchResult'=>$searchResult));
}
I do not think that this is a AJAX Problem (definded by PageNum).
If I call the controller Action without AJAX the same error appears ...
You can't use renderPartial() oder renderSection() from extbase/php in StandaloneView. It's a missing feature that will probably not be implemented in TYPO3 7.6 and below. See this task: https://forge.typo3.org/issues/54509
However, you can use partials and sections in Fluid. Just assign your variables, then render your template with
$this->templateView->render();
And use partials and section in your Fluid template.

Laravel Pagination with appends() Error

I am new to Laravel and am using version 4.1.
I am attempting to query database using pagination and then run the results through the appends() function to add additional parameters to my URL.
Here is the code I am using
$query = DB::table('tableName');
$query->paginate(50);
$results = $query->get();
And that runs as desired. Now when I attempt to create the pagination list (Bootstrap default) and run the following code I get an error.
$pagination = $results->appends(array('key' => 'value'))->links();
This is the error I receive.
Call to a member function appends() on a non-object
I know I'm doing something wrong, I just can't figure out what...
Thanks in advance,
SC
I'm not familiar with the appends function, but you do have an error I can see. Try changing
$query = DB::table('tableName');
$query->paginate(50);
$results = $query->get();
To...
$query = DB::table('tableName');
if(Input::has('someinput')) {
$query->where('someinput', Input::get('someinput'));
}
if(Input::has('otherinput')) {
$query->where('otherinput', Input::get('otherinput'));
}
$results = $query->paginate(50);
Once you run paginate(), an instance of Paginator is returned. I don't see a get() method for Paginator though so I'm not sure how you weren't getting an error there.

Codeigniter PHP Missing Argument 2 Error?

I'm having an issue with my correctly displaying my URLs for my website. I'm using the latest version of Codeigniter.
I'm getting the below error message. I was doing some research and I think my issue is URI segments but I'm perplexed as to how to fix the problem.
My goal is to get the URL to look nice this
(_states is a sub directory folder on my localhost)
mydomain.com/_states/dealers/Florida (This URL actually works)
mydomain.com/_states/dealers/Florida/Miami (not working)
mydomain.com/_states/dealers/Florida/Miami/8 (not working)
I've also provided the syntax for my routes.php and model_data.php. How would you guys going about fixing this problem? Thanks everyone in advance.
A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Site::getDealersCity()
Filename: controllers/site.php
Line Number: 43
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: city
Filename: controllers/site.php
Line Number: 47
Site Controller
public function getDealersCity($state, $city){
//$city = $this->uri->segment(3);
//echo "$city";
if(is_null($state)) return false;
if(is_null($city)) return false;
$this->load->model('model_data');
$data['statecity'] = $this->model_data->get_database_by_cities($state,$city);
$this->load->view('statecity',$data);
}
Model_data.php function
function get_database_by_cities($state, $city){
$query = $this->db->get_where('states',
array('state' => $state,
'city' => $city)
);
if($query->num_rows()) return $query->result();
return null;
}
Routes.php
$route['default_controller'] = "site";
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";
$route['dealers/(:any)'] = "site/getCities/$1";
$route['404_override'] = '';
$route['dealers/(:any)/(:any)'] = "site/getUniqueDealerInfo/$3";
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$2";
The routes are conflicting in nature, one route overrides other.
Try using
$route['dealers/(:any)/(:any)'] = "site/getDealersCity/$1/$2";
And there is no function for
getUniqueDealerInfo
Have a look at the answers here Similar Question

Resources