Codeigniter4 Routing Failing - php

I have a problem with routing on my website as it's not working at all. At the beginning I wanted to have different Controllers for differetn tabs, but in the end I have changed that to view pages from the Home controller, but even that doesnt work.
Here is my Home controller - index and connection to Model works fine but the travel() function doesnt
<?php
namespace App\Controllers;
use App\Models\HomeMod;
use \Codeigniter\Controller;
class Home extends BaseController {
public function index() {
$this->homeMod = new HomeMod();
$data = array();
$data['total'] = number_format($this->totalCases('total'));
echo view('header');
echo view('welcome_message', $data);
echo view('footer');
}
protected function totalCases(String $columnName) : String{
$result = $this->homeMod->findColumn($columnName);
return count($result) > 0 ? $result[0] : "0";
}
public function travel() {
return view('travel');
}
public function getPostCodeCases() {
if(!IS_AJAX) return;
var_dump("inside");
die();
}
}
I cannot reach the getPostCodeCases() function either (the ajax call in js file works fine, its just not reaching this function).
And my routes file - as you can see i have tries with different variations
$routes->get('/', 'Home::index');
// $routes->get('/getPostCodeCases', 'Home::getPostCodeCases');
$routes->post('/getPostCodeCases', 'Home::getPostCodeCases');
$routes->match(['get', 'post'],'/getPostCodeCases', 'Home::getPostCodeCases');
$routes->get("travel", "Travel::index");
// $routes->add('/travel', 'Travel::index');
// $routes->add('travel', 'Home::travel');
// $routes->add('/travel/(:any)', 'Travel::index');
My base url: https://localhost/CI and $indexPage = '' (in App.php).
I am sure I have missed something, somewhere but not sure where...
Could someone help me to resolve this problem ?

Related

Laravel routing white page with Controller

I'm using Laravel 8.
I'm trying to save ip addresses who visited the page. I can save it to the database. But there is a white page problem on page. How can i solve this problem? Thanks.
web.php
Route::get('/', [IpController::class,'addData'], function () {
$slides = App\Slide::all();
$themes = App\Theme::all();
return view('tema.kurumsal.index', compact('slides','themes'));
});
IpController.php
class IpController extends Controller
{
//
function addData(Request $req)
{
$ip = new Ip;
$ip->ip = $req->ip();
$ip->cihaz = $req->userAgent();
$ip->url = $req->getRequestUri();
$ip->save();
}
}
There is no 3rd parameter on Route::get, so what is that function doing ? This is the Source code.
You have a white page because you are not returning a view or data on your IpController.
Have another look at the documentation. There is no 3rd parameter.
Your code should be like this:
Route::get('/', [IpController::class,'addData']);
And your controller:
class IpController extends Controller
{
public function addData(Request $req)
{
$ip = new Ip;
$ip->ip = $req->ip();
$ip->cihaz = $req->userAgent();
$ip->url = $req->getRequestUri();
$ip->save();
$slides = \App\Slide::all();
$themes = \App\Theme::all();
return view('tema.kurumsal.index', compact('slides','themes'));
}
}

CakePHP 4 sub view or sub action routing

In cakePHP 4
I have a controller and view.php connected with it.
I can use a route like this: sitename.com/projects/45, where 45 - is sample project ID.
Using this url I can reach a page with the content of particular project. But If I want to construct something like a page of settings of this project, how I have to do it?
For example via url sitename.com/projects/45/settings
Help please
It's simple:
// sitename.com/projects/45
// public function view($id) { ... }
// sitename.com/projects/45/settings
public function view($id, $passed = null) {
if($passed == 'settings') {
// do ...
}
}
or
public function view($id) {
$passed = $this->getRequest()->getParam('pass');
if (in_array('settings', $passed)) {
// do ...
}
}

Added new method to the controller doesn't work in codeigniter

I am working on an existing project developed by codeigniter 2.1.4. When I add a new method to a controller and run it to the browser, it shows nothing. Even other methods under that controller also don't run if new method added to that controller. These controllers extends the following controller:
<?php
class MY_Controller extends CI_Controller {
public $data = array();
public $allowedUrl = array(
"super admin" => array("case_controllerler/deleteSingleCase","case_controller/quickPendingCaseSearch","case_controller/checkUniqueCaseNumber","case_controller/kharijCase","admin/index","case_controller/viewSatalementKhatianCopyApplication", "admin/saveAdmin","admin/addUser", "admin/allAdmin", "admin/suspendUser", "admin/activeUser", "admin/CustomSearchGL","admin/showMethod","admin/CustomSearchAction","admin/deleteUser","admin/showAllComplain","admin/singleAdminInfo","admin/updateAdminInfo","admin/successfullyUpdated","case_controller/downloadPendingCase",
"case_controller/addCase", "case_controller/store_data", "case_controller/caseSuccessfullyAdded", "case_controller/createCalender",
"case_controller/workingDaysCalender", "case_controller/editPendingCase","case_controller/saveEditedPendingCase","case_controller/EditmissCase","case_controller/UpdateMisccase",
"case_controller/pending", "case_controller/allCase", "case_controller/searchCase", "case_controller/singleCase","case_controller/testAjax","case_controller/DeleteLandData","case_controller/SaveNEwLandInfo","case_controller/DeleteApplicantinfo",
"case_controller/nextDateFromGivenDate","case_controller/downloadArchiveCase","case_controller/sendSms","case_controller/secondSms","case_controller/thirdSms","case_controller/fourthSms","case_controller/fiveSms","case_controller/CustomSms","case_controller/monthAllreadyExit",
"register_control/AddTohsil","register_control/TohsilEntry","register_control/EditTohsil","register_control/updatetohsil",
"register_control/AddMouja","register_control/MoujaEntry","register_control/EditMouja","register_control/updateMouja",
"register_control/AddMutationAsistant","register_control/MutationAsistantEntry","register_control/EditMutationAsistant","register_control/updateMutationAsistant",
"register_control/AddKhotiyan","register_control/moujaquery","register_control/saveKhotiyan","register_control/saveKhotiyanFile",
"register_control/FindKhotiyan","register_control/SearchKhotiyan","register_control/DeleteKhotiyan","register_control/Editkhotiyan",
"register_control/AddNewKhotiyanUnderKhotiyanId","register_control/saveNewKhotiyan","register_control/UpdateKhotiyan","register_control/Getjolmohol",
"register_control/Tamil","register_control/EntryTamilFormat","register_control/createcellfortamil","register_control/editTamil","register_control/UpdateTamil","register_control/DeleteTamil","register_control/Imgdownload",
"dashboard/DashboardHome","dashboard/viewFullreport","dashboard/tohsilviewlist","dashboard/tohsilviewlistoverdate","dashboard/namjariviewlist","dashboard/namjariviewlistoverdate","dashboard/kanongopendingviewlist","dashboard/kanongooverdateviewlist","dashboard/aclandPendingeviewlist","dashboard/aclandoverdateviewlist","dashboard/waitingpendingviewlist","dashboard/waitingooverdateviewlist",
"admin/DeleteComplains","admin/fullviewcomplains", "register_nine/Newentry","register_nine/SaveData","register_nine/Search","register_nine/viewapplication",
"register_nine/editapplication","register_nine/Deleteapplication","register_nine/Preview","register_nine/UpdateApplication",
"register_nine/SearchForPreview","register_nine/paginationData","admin/GovLandEntry","admin/savegovtLandInfo","admin/GovLandQuery","admin/govtLandInfoQuery","admin/EditGovtLand",
"admin/UpdategovtLandInfo","admin/DeleteGovtLandInfo","admin/govtLandInfoQueryByType",
"case_controller/AddmissCase","case_controller/SaveMissCase","case_controller/MIssCassUpdate","case_controller/UpdateInfoMissCase","case_controller/MiscSmsToplaintiff",
"case_controller/EditMIssCaseUpdate","case_controller/UpdateStatus","case_controller/DeletemissCasestatus","case_controller/CheckGovtLand",
"case_controller/FinishMisscase","case_controller/DeletemissCase","case_controller/ArchivemissCase","case_controller/ViewMIssCassUpdate","case_controller/SearchActionByNameOrNId","case_controller/SearchActionBydag",
"case_controller/SearchmissCase","case_controller/SearchMisscaseAction","case_controller/viewPorcaApplication","case_controller/DeletePorcaapplication","case_controller/ArchivePorcaApplication","case_controller/approvalsms",
"case_controller/ApprovePoRcaApliCation","case_controller/fullviewPrcaApplication","register_control/RemoveKhotiyanFile","case_controller/SaveMissCaseAttchment",
"register_control/DeleteKHotiyanFile","register_control/ViewTamil","register_control/NewAddKhotiyanFile","register_control/TamilDownload","register_control/RegisterONe","register_control/FileInventory"
,"other_registers/EntryDailyIncome","other_registers/SaveDailyINcome","other_registers/inqueryAndSubmit","other_registers/SearchActionOfInquery","other_registers/DeliveryToBank","other_registers/deliverySuccess",
"other_registers/searchCashRegister","other_registers/SearchActionregisterthree","other_registers/SearchActionregisterthreebyStauts","other_registers/registerseventeenOfTohsil","other_registers/DemandRegister","other_registers/miscellenousPaymentRegister",
"other_registers/registerseventeenOfAcland","admin/showAllOpinion","admin/Deleteopinion","admin/fullviewopinion","mutation_controller/DownloadMutationApplication","mutation_controller/AllMutationApplications","mutation_controller/DetailsMutationAppliCation",
"mutation_controller/accecptApplicationSms","mutation_controller/DeleteMutationApplication","dashboard/TohsilPieChart","other_registers/SavedemandRegisterSix","other_registers/SearchAndDelivaryRegisterSix"
,"other_registers/SearchActionOfInqueryRegisterSix","other_registers/RegisterSixDelivery","other_registers/registerSixdeliverySuccess","other_registers/SavePaymentRegisterSeven",
"other_registers/SearchAndDelivaryRegisterSeven","other_registers/SearchActionOfInqueryRegisterSeven","other_registers/RegisterSevenDelivery","other_registers/registerSevendeliverySuccess","case_controller/ChangeMutationAsistant",
"case_controller/ActionChangeMutationAsistant","case_controller/FeedbackMiscCaseUpdate","case_controller/FeedbackUpdateInfoMissCase","admin/EditUser","admin/updateAdminInfobySuperAdmin", "case_controller/EditMIssCaseUpdateFeedback",
"case_controller/UpdateStatusFeedback","case_controller/PrintMIsscassInformation","case_controller/viewArchiveCase","case_controller/deleteArchiveSingleCase","case_controller/RuningMiscCase","dashboard/CaseCounter",
"other_registers/deleteDailyEntryRegisterThree","other_registers/deleteDailyEntryRegistersix","other_registers/deleteDailyEntryRegisterseven","case_controller/fullviewArchivePrcaApplication","case_controller/OrderSheet","case_controller/SaveOrderInfo","case_controller/PrintOrderSheet",
"case_controller/ViewLedger","case_controller/ProposalView","case_controller/SaveProposalInfo","case_controller/PrintProposalView","case_controller/CaseNotice","case_controller/PrintNoticeView","case_controller/SecondPagePrintProposalView",
"case_controller/UpdateCaseLandInfo","case_controller/SaveScratchMap","case_controller/UpdateCaseApplicantInfo","case_controller/TohsilWisePendingCaselist"),
"admin" => array("case_controller/addCase","case_controller/organizeDateFormat","case_controller/createCalender","case_controller/EditmissCase","case_controller/UpdateMisccase","case_controller/DeleteLandData","case_controller/SaveNEwLandInfo","case_controller/DeleteApplicantinfo",
"case_controller/assendingCalender","case_controller/monthAllreadyExit","case_controller/changeDateFromat","case_controller/testAjax","case_controller/nextDateFromGivenDate",
"case_controller/store_data","case_controller/caseSuccessfullyAdded","case_controller/allCase","case_controller/searchCase","case_controller/singleCase",
"case_controller/pending","case_controller/quickPendingCaseSearch","case_controller/kharijCase","case_controller/editPendingCase","case_controller/saveEditedPendingCase",
"case_controller/downloadArchiveCase","case_controller/downloadPendingCase","case_controller/sendSms","case_controller/secondSms","case_controller/thirdSms",
"case_controller/fourthSms","case_controller/fiveSms","case_controller/CustomSms","case_controller/checkUniqueCaseNumber","case_controller/AddmissCase","case_controller/MiscSmsToplaintiff","case_controller/ViewLedger","case_controller/CaseNotice",
"case_controller/SaveMissCase","case_controller/MIssCassUpdate","case_controller/UpdateInfoMissCase","case_controller/EditMIssCaseUpdate","case_controller/UpdateStatus",
"case_controller/FinishMisscase","case_controller/ArchivemissCase","case_controller/ViewMIssCassUpdate","case_controller/RuningMiscCase","case_controller/SaveMissCaseAttchment",
"case_controller/SearchmissCase","case_controller/SearchMisscaseAction","case_controller/viewPorcaApplication","case_controller/ArchivePorcaApplication",
"case_controller/ApprovePoRcaApliCation","case_controller/fullviewPrcaApplication","case_controller/SearchActionByNameOrNId","case_controller/SearchActionBydag",
"case_controller/approvalsms","case_controller/ChangeMutationAsistant","case_controller/ActionChangeMutationAsistant","case_controller/FeedbackMiscCaseUpdate",
"case_controller/FeedbackUpdateInfoMissCase","case_controller/EditMIssCaseUpdateFeedback","case_controller/UpdateStatusFeedback","case_controller/PrintMIsscassInformation",
"case_controller/viewArchiveCase","case_controller/RuningMiscCase","case_controller/viewSatalementKhatianCopyApplication","case_controller/fullviewArchivePrcaApplication",
"dashboard/DashboardHome","dashboard/viewFullreport","dashboard/tohsilviewlist","dashboard/tohsilviewlistoverdate","dashboard/namjariviewlist",
"dashboard/namjariviewlistoverdate","dashboard/kanongopendingviewlist","dashboard/kanongooverdateviewlist","dashboard/aclandPendingeviewlist",
"dashboard/aclandoverdateviewlist","dashboard/waitingpendingviewlist","dashboard/waitingooverdateviewlist","dashboard/TohsilPieChart","dashboard/CaseCounter",
"mutation_controller/AllMutationApplications","mutation_controller/DetailsMutationAppliCation","mutation_controller/DownloadMutationApplication",
"mutation_controller/accecptApplicationSms","mutation_controller/DeleteMutationApplication","mutation_controller/MutationForm",
"other_registers/EntryDailyIncome","other_registers/SaveDailyINcome","other_registers/inqueryAndSubmit","other_registers/SearchActionOfInquery",
"other_registers/searchCashRegister","other_registers/SearchActionregisterthree","other_registers/SearchActionregisterthree","other_registers/SearchActionregisterthreebyStauts",
"other_registers/registerseventeenOfTohsil","other_registers/DemandRegister","other_registers/miscellenousPaymentRegister","other_registers/registerseventeenOfAcland",
"other_registers/SavedemandRegisterSix","other_registers/SearchAndDelivaryRegisterSix","other_registers/SearchActionOfInqueryRegisterSix","other_registers/RegisterSixDelivery",
"other_registers/registerSixdeliverySuccess","other_registers/SavePaymentRegisterSeven","other_registers/SearchAndDelivaryRegisterSeven",
"other_registers/SearchActionOfInqueryRegisterSeven","other_registers/RegisterSevenDelivery","other_registers/registerSevendeliverySuccess",
"register_control/moujaquery","register_control/getmoujaAndMObile","register_control/AddKhotiyan","register_control/saveKhotiyan","register_control/saveKhotiyanFile",
"register_control/NewAddKhotiyanFile","register_control/FindKhotiyan","register_control/SearchKhotiyan","register_control/Editkhotiyan","register_control/UpdateKhotiyan",
"register_control/Tamil","register_control/createcellfortamil","register_control/EntryTamilFormat","register_control/editTamil","register_control/UpdateTamil",
"register_control/ViewTamil","register_control/Imgdownload","register_control/TamilDownload","register_control/RegisterONe","register_control/Getjolmohol",
"admin/index","admin/singleAdminInfo","admin/updateAdminInfo","admin/successfullyUpdated","admin/GovLandEntry","admin/savegovtLandInfo","admin/GovLandQuery","admin/govtLandInfoQuery",
"admin/EditGovtLand","admin/UpdategovtLandInfo","admin/govtLandInfoQueryByType","admin/allAdmin","admin/CustomSearchGL","admin/showMethod","admin/CustomSearchAction",
"register_nine/Newentry","register_nine/Search","register_nine/viewapplication","register_nine/editapplication","register_nine/UpdateApplication",
"register_nine/Preview","register_nine/SearchForPreview","register_nine/paginationData","case_controller/UpdateCaseLandInfo","case_controller/SaveScratchMap","case_controller/UpdateCaseApplicantInfo"),
"general user" => array("case_controller/quickPendingCaseSearch","case_controller/kharijCase","case_controller/pending", "case_controller/allCase", "case_controller/searchCase", "case_controller/singleCase", "admin/index","case_controller/downloadPendingCase","admin/singleAdminInfo","admin/updateAdminInfo","admin/successfullyUpdated",)
);
public function __construct() {
parent::__construct();
$this->isLoggedIn();
$this->isPermitedToAccess();
}
public function isLoggedIn() {
if ($this->session->userdata('logged_in') === FALSE) {
redirect('login/index');
}
}
//end of the is logged in
public function isPermitedToAccess() {
$userType = $this->session->userdata("type");
$currentUrl = $this->uri->segment(1) . "/" . $this->uri->segment(2);
if (array_search($currentUrl, $this->allowedUrl[$userType]) === FALSE) {
redirect("admin/index");
}
}
}
I tried to add my new method to $allowedUrl variable. But it didn't work. Can any one please give me any idea to solve this problem. I am stuck on it.
Did you try to assign the value for $allowedUrl inside __construct function, I think it will work!

cant get passed parameter by url in php

please help me, this is simple thing but I don't know why this still keep error for an hour,
on my view I've got :
<a href="admin/editProduct?idd=$id">
on my controller that directed from above :
public function editProduct(){
$data["id"] = $_GET['idd'];
$data["produk"] = $this->model_get->get_data_list(2);
//this below doesn't work either, i just want to past the parameter to my model
//$data["produk"] = $this->model_get->get_data_list($_GET['idd']);
$this->adminHeader();
$this->load->view("adminPages/editProduct", $data);
$this->adminFooter();
}
I can not use the array id. It keeps telling me undefined variable idd.
I don't know what to do anymore, please anyone help!
I am using Codeigniter framework
Change your view as:
<a href="admin/editProduct/<?php echo $id;?>">
And in the controller, either get the id as parameter,
public function editProduct($id) {
}
or as uri segment
public function editProduct() {
$id = $this->uri->segment(3);
}
Change your link (in view) with this
<a href="admin/editProduct/$id">
And change your controller as
public function editProduct($id) {
}
Then user $id inside your controller
Make the href link as follows:
...
And edit the controller like this:
public function editProduct($id){
...
$this->model_get->get_data_list($id);
}
Where $id will be the passed $id.
make
try this this works fine
public function editProduct()
{
$id=$this->uri->segment(3);
$data["produk"] = $this->model_get->get_data_list($id);
$this->adminHeader();
$this->load->view("adminPages/editProduct", $data);
$this->adminFooter();
}

How do I use a controller within a controller?

I am using Kohana 3.2 and I am having problems calling the ouput of a controller in another controller.
What I want...
In some pages I have got a menu, and in others I don't. I want to use make use of the flexability of the HMVC request system. In the controller of a page I want to call another controller which is responsible for the creation of the menu.
What I have a the moment:
file menu.php:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Menu extends Controller
{
private $_model = null;
public function __construct(Request $request, Response $response)
{
parent::__construct($request, $response);
$this->_model = Model::factory('menu');
}
public function action_getMenu()
{
$content = array();
$content['menuItems'] = $this->_model->getMenuItems();
// Render and output.
$this->request->response = View::factory('blocks/menu', $content);
//echo '<pre>'; print_r($this->request->response->render()); echo '</pre>'; die();
}
}
somepage.php
public function action_index()
{
$this->template->title = 'someTitle';;
$contentData['pageTitle'] = 'someTitle';
$contentData['contentData'] = 'someData';
#include the menu
$menuBlock = Request::factory('menu/getMenu')->execute();
$menuData = array('menu' => $menuBlock);
$this->template->menu = View::factory('pages/menu')->set('menu',$menuData);
$this->template->content = View::factory('pages/somePage', $contentData);
$view = $this->response->body($this->template);
$this->response->body($view);
}
If I uncomment the following line in menu.php, I see the menu rendered:
//echo '<pre>'; print_r($this->request->response->render()); echo '</pre>'; die();
So I guess that part is alright. The problem is in the following line in somepage.php:
$menuBlock = Request::factory('menu/getMenu')->execute();
This gives me back a response object. Whatever I do, I do not get the output in $this->template->menu.
$this->template->menu = View::factory('pages/menu')->set('menu',$menuData);
What must I do to have $this->template->menu contain the view, so I can use it correctly?
I hope this all makes sense. This is the way I would like to do it, but maybe I am completely on the wrong track.
I would do it this way:
class Controller_Menu extends Controller
{
public function action_build()
{
// Load the menu view.
$view = View::factory('navigation/menu');
// Return view as response-
$this->response->body($view->render());
}
}
In your controller get the menu as follows:
// Make request and get response body.
$menu = Request::factory('menu/build')->execute()->body();
// e.g. assign menu to template sidebar.
$this->template->sidebar = Request:.factory('menu/build')->execute()->body();
I would not use the __construct method in your controllers. Use before() instead, this is sufficient for most of the problems (for example auth):
public function before()
{
// Call aprent before, must be done here.
parent::before();
// e.g. heck whether user is logged in.
if ( !Auth::instance()->logged_in() )
{
//Redirect if not logged in or something like this.
}
}
I found the answer to my problem in less than an hour after asking.
I just forgot to put it here.
In somePage.php change :
$menuBlock = Request::factory('menu/getMenu')->execute();
$menuData = array('menu' => $menuBlock);
$this->template->menu = View::factory('pages/menu')->set('menu',$menuData);
To:
$this->template->menu = Request::factory('menu/getMenuBlock')->execute()->body();
And in menu.php change:
$this->request->response = View::factory('blocks/menu', $content);
To:
$request = View::factory('blocks/menu', $content);
$this->response->body($request);
I hope this will help someone else.

Categories