Codeigniter PHP Missing Argument 2 Error? - codeigniter

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

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

How can I return a random asset from specific folder?

I need to create a route where a random image or video is returned from a specific directory, how can I achieve this?
perhaps something like this
Route::get('/random_media/', function() {
// Get random files and pick one.
$folder_path = public_path()."/your/path/here/"; // in my test case it's under /public folder
$files = preg_grep('~\.(jpeg|jpg|png)$~', scandir($folder_path));
$randomFile = $files[array_rand($files)]; // if 5 files found, random int between 0 and 4
// Display it
$file = File::get($folder_path.$randomFile);
$response = Response::make($file, 200);
$response->header('Content-Type', mime_content_type($folder_path.$randomFile));
return $response;
});
Using preg_grep instead of glob(). see this answer: https://stackoverflow.com/a/8541256/2468160
If you see an error message (like I did) Fatal error Call to undefined function finfo_open() ---->
Fatal error: Call to undefined function finfo_open() in php
My laravel version is 5.2.39, but I hope it works on 5.1.*

Symfony 2: session_start causes ERR_EMPTY_RESPONSE

We just moved our Symfony2.3 project to another server and now we encounter the following problem:
The routes /login and _wdt/9d5405 result in a ERR_EMPTY_RESPONSE error in Google Chrome (and all other browsers showing their specific error messages). The error occurs in both, prod and dev environment.
I tracked down the issue from my loginAction
/**
* #Route("/login", name="login")
* #Route("/login/{redirect}", name="login_redirect")
* #Template()
*/
public function loginAction($redirect = '')
{
if ($this->getUser())
{
return $this->redirect($this->generateUrl('crea_frontend_index'));
}
$request = $this->getRequest();
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
{
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
}
else
{
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
$redirect = urldecode($redirect);
return array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME), // last username entered by the user
'redirect' => $redirect,
'error' => $error,
);
}
This line produces the error:
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
And I tracked it down to
Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
and there in line 148 if (!session_start()) {.
So it turnes out that session_start at this point produces the error but when I add a session_start(); to app.php and comment everything else it works.
Now I am completely puzzled on how to fix this. Any ideas on how to solve this or just how to further debug would be very appriciated.
PHP 5.4.20
No errors in logfiles
UPDATE
The error seems to be somehow related to these bug discussions:
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/424789
https://bugs.gentoo.org/show_bug.cgi?id=276583
UPDATE
Solved: The Problem was the PHP Version 5.4.20. We tested 5.3.17 and 5.5.9. Both function well. Except 5.4.20. But I still want to know what exaclty causes this error. This could then result in a Symfony fix to deal with this version.

Codeigniter Pagination cannot initialize

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.

Resources