how can i hide controller name from the url in codeigniter - codeigniter

i have both admin panel and also one more front panel.....i have different controller for both and in my routes.php i made changes but because of that some links are not working
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['contact'] = 'site/contact';
$route['events'] = 'site/events';
$route['terms'] = 'site/terms';
$route['privacy'] = 'site/privacy';
$route['newevent'] = 'site/add_event';
$route['(:any)'] = "site/$1";
//$route['(:any)'] = "backos/$1";
$route['listevents'] = 'backos/events';
$route['listwhatsapp'] = 'backos/whatsapp';
$route['add_artist'] = 'backos/add_artist';
$route['add_club'] = 'backos/add_club';
$route['index'] = 'backos/index';
$route['check'] = 'backos/check';
$route['add_event'] = 'backos/add_event';
$route['add_city'] = 'backos/add_city';
$route['add_locality'] = 'backos/add_locality';
//$route['(:any)'] = "backos/$1";
this is my routes.php file.

try this...
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['contact'] = 'site/contact';
$route['events'] = 'site/events';
$route['terms'] = 'site/terms';
$route['privacy'] = 'site/privacy';
$route['newevent'] = 'site/add_event';
$route['listevents'] = 'backos/events';
$route['listwhatsapp'] = 'backos/whatsapp';
$route['add_artist'] = 'backos/add_artist';
$route['add_club'] = 'backos/add_club';
$route['index'] = 'backos/index';
$route['check'] = 'backos/check';
$route['add_event'] = 'backos/add_event';
$route['add_city'] = 'backos/add_city';
$route['add_locality'] = 'backos/add_locality';
// this is a catch all if you don't put it as
// the last one everything else below it wont work!
$route['(:any)'] = "site/$1";

Related

Save ID two columns Laravel

I want to save the ID of a new Sale(); in $sale->voucher_series, how can I achieve this?
$sale = new Sale();
$sale->customerid = $request->customerid;
$sale->userid = \Auth::user()->id;
$sale->proof_type = $request->proof_type;
$sale->voucher_series = $request->saleId;
$sale->date_time = $mytime->toDateString();
$sale->total = $request->total;
$sale->status = 'Registered';
$sale->save();
If your voucher_series column is nullable field then it will work.
$sale = new Sale ();
$sale->customerid = $request->customerid;
$sale->userid = \Auth :: user()->id;
$sale->proof_type = $request->proof_type;
$sale->date_time = $mytime->toDateString ();
$sale->total = $request->total;
$sale->status = 'Registered';
$sale->save();
$sale->voucher_series = $sale->id;

how to store the primary key values to the foreign key at same time of save

I am new to the laravel and trying to store the primary key values of patientid to the foreign key of patient_id in address table
$patdet = $request->patdet;
foreach ($patdet as $patdets) {
$pdet = new Patient();
$pdet->fname = $patdets['fname'];
$pdet->mname = $patdets['mname'];
$pdet->lname = $patdets['lname'];
$pdet->age = $patdets['age'];
$pdet->blood_group = $patdets['bloodgroup'];
$pdet->gender = $patdets['gender'];
$ptid = $pdet->save();
}
$addr = $request->address[0];
$address = new Address;
$address->gps_lat = $addr['gps_lat'];
$address->gps_log = $addr['gps_long'];
$address->house_no = $addr['houseno'];
$address->zipcode = $addr['zip_code'];
$address->street = $addr['street'];
$address->chowk = $addr['chowk'];
$address->city = $addr['city'];
$address->patient_id = $patid->id;
$address->save();
I know that $ptid is a local variable and cannot be used in address table, so how can I store it in address table?
Try the following and ask me if it doesn't work
foreach($request->patdet as $key => $patdets)
{
$pdet = new Patient();
$pdet->fname = $patdets['fname'];
$pdet->mname = $patdets['mname'];
$pdet->lname = $patdets['lname'];
$pdet->age = $patdets['age'];
$pdet->blood_group = $patdets['bloodgroup'];
$pdet->gender = $patdets['gender'];
$pdet->save();
$addr = $request->address[$key];
if($pdet->id > 0 && !empty($addr)){
$addrss = new Address;
$addrss->gps_lat = $addr['gps_lat'];
$addrss->gps_log = $addr['gps_long'];
$addrss->house_no = $addr['houseno'];
$addrss->zipcode = $addr['zip_code'];
$addrss->street = $addr['street'];
$addrss->chowk = $addr['chowk'];
$addrss->city = $addr['city'];
$addrss->patient_id = $pdet->id;
$addrss->save();
}
}
Try the following
$patArray = $request->patdet;
$addressArray = $request->address;
$pId = array();
foreach($patArray as $key => $patdets){
$pdet = new Patient();
$pdet->fname = $patdets['fname'];
$pdet->mname = $patdets['mname'];
$pdet->lname = $patdets['lname'];
$pdet->age = $patdets['age'];
$pdet->blood_group = $patdets['bloodgroup'];
$pdet->gender = $patdets['gender'];
$pdet->save();
$pId[$key] = ($pdet->id > 0) ? $pdet->id : 0;
}
foreach($addressArray as $key => $addr){
$addrss = new Address;
$addrss->gps_lat = $addr['gps_lat'];
$addrss->gps_log = $addr['gps_long'];
$addrss->house_no = $addr['houseno'];
$addrss->zipcode = $addr['zip_code'];
$addrss->street = $addr['street'];
$addrss->chowk = $addr['chowk'];
$addrss->city = $addr['city'];
$addrss->patient_id = array_key_exists($key ,$pId) ? $pId[$key] : 0;
$addrss->save();
$i++;
}

when i store function submit from create blade i get this error "Array to string conversion"

This is my controller in store function save for ministries table.
$ministries = new Ministry;
$ministries->country_id = $request->country_name;
$ministries->township_id = $request->township_name;
$ministries->city_id = $request->city_name;
$ministries->division_id = $request->division_name;
$ministries->ministryCode = $request->ministry_code;
$ministries->ministryName = $request->ministry_name;
$ministries->ministryNameMm = $request->ministry_mm_name;
$ministries->address = $request->address;
$ministries->phone = $request->phone;
$ministries->fax = $request->fax;
$ministries->email = $request->email;
$ministries->website = $request->website;
$ministries->save();
$ministries_id = $ministries->id;
this is save for other table(contact_persons)
for ($i=0; $i < count($request->position_id); $i++) {
$contact_persons = new ContactPerson();
$contact_persons->responsibility_id = $request->responsibility_id[$i];
$contact_persons->position_id = $request->position_id[$i];
$contact_persons->country_id = $request->email[$i];
$contact_persons->township_id = $request->email[$i];
$contact_persons->city_id = $request->email[$i];
$contact_persons->division_id = $request->email[$i];
$contact_persons->customer_id = $request->email[$i];
$contact_persons->address = $request->email[$i];
$contact_persons->home_phone = $request->email[$i];
$contact_persons->mobile = $request->email[$i];
$contact_persons->email = $request->email[$i];
$contact_persons->ministries_id = $ministries_id;
$contact_persons->save();
}
please how to solve and thanks.

Codeigniter routes subfolder not working

$route['default_controller'] = "index";
$route['404_override'] = '';
$route['(:any)'] = 'index/$1';
$route['admin'] = "admin/index";
$route['admin/add_category'] = "admin/index/add_category";
Works :
$route['admin/edit_category/2'] = "admin/index/edit_category/2";
Not working :
$route['admin/edit_category/(:any)'] = "admin/index/edit_category/$1";
Try to put Your rule before route which catches everything
$route['admin'] = "admin/index"; // no params at first
$route['admin/add_category'] = "admin/index/add_category"; // extend first rule
$route['admin/edit_category/(:any)'] = "admin/index/edit_category/$1"; // and one more
$route['default_controller'] = "index"; // default settings
$route['404_override'] = '';
$route['(:any)'] = 'index/$1'; // ok, now we can brake MVC pattern, but should we?
for example one of my route-files (works for sure):
$route['project-admin/login'] = "project-cms/user/index";
$route['project-admin/recovery'] = "project-cms/user/recovery";
$route['project-admin'] = "project-cms/admin/index";
$route['project-admin/(:any)'] = "project-cms/admin/$1";
$route['project-admin/(:any)/(:any)'] = "project-cms/admin/$1/$2";

CodeIgniter - Active Record returning empty results with Access ODBC

I'm connecting to an Access DB via mdbtools on a Linux system and on running any query via Active Record it returns an empty result. No errors or anything to show in the logs. Any ideas ? It connects to the database without a hitch and I have no problem accessing the tables or running queries with the default PHP method (e.g. odbc_exec(...)).
The DB Connection looks like this:
$db['access']['hostname'] = 'MyDB';
$db['access']['username'] = '';
$db['access']['password'] = '';
$db['access']['database'] = 'MyDB';
$db['access']['dbdriver'] = 'odbc';
$db['access']['dbprefix'] = '';
$db['access']['pconnect'] = TRUE;
$db['access']['db_debug'] = TRUE;
$db['access']['cache_on'] = FALSE;
$db['access']['cachedir'] = '';
$db['access']['char_set'] = 'utf8';
$db['access']['dbcollat'] = 'utf8_general_ci';
$db['access']['swap_pre'] = '';
$db['access']['autoinit'] = TRUE;
$db['access']['stricton'] = FALSE;
The odbc.ini looks like:
[MyDB]
Description = My Database
Driver = /usr/lib64/libmdbodbc.so
Database = /var/database/MyDB.mdb
Connecting with:
$this->access = $this->load->database('access', TRUE);
I do not have microsoft access database to test with the following configuration, but I think this should be able to give you an idea to experience with different configuration. You can specify data source name in your configuration and I collected the settings from codeigniter forum and merge with yours.
$db['access']['hostname'] = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=/var/database/MyDB.mdb";
$db['access']['username'] = "ADODB.Connection";
$db['access']['password'] = "";
$db['access']['database'] = "/var/database/MyDB.mdb";
$db['access']['dbdriver'] = "odbc";
$db['access']['dbprefix'] = "";
$db['access']['pconnect'] = TRUE;
$db['access']['db_debug'] = TRUE;
$db['access']['cache_on'] = FALSE;
$db['access']['cachedir'] = "";
$db['access']['char_set'] = "utf8";
$db['access']['dbcollat'] = "utf8_general_ci";
$db['access']['swap_pre'] = "";
$db['access']['autoinit'] = TRUE;
$db['access']['stricton'] = FALSE;

Resources